tcldcc.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. /*
  2. * tcldcc.c -- handles:
  3. * Tcl stubs for the dcc commands
  4. *
  5. */
  6. #include "main.h"
  7. #include "tandem.h"
  8. #include "modules.h"
  9. #include <sys/stat.h>
  10. extern Tcl_Interp *interp;
  11. extern tcl_timer_t *timer,
  12. *utimer;
  13. extern struct dcc_t *dcc;
  14. extern int dcc_total, backgrd, parties,
  15. do_restart, remote_boots, max_dcc, hub, leaf;
  16. extern char botnetnick[], netpass[], *binname;
  17. extern party_t *party;
  18. extern tand_t *tandbot;
  19. extern time_t now;
  20. /* Traffic stuff. */
  21. extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc, itraffic_irc_today, otraffic_bn, otraffic_bn_today, itraffic_bn, itraffic_bn_today, otraffic_dcc, otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today, otraffic_trans, otraffic_trans_today, itraffic_trans, itraffic_trans_today, otraffic_unknown, otraffic_unknown_today, itraffic_unknown, itraffic_unknown_today;
  22. int enable_simul = 0;
  23. static struct portmap *root = NULL;
  24. int expmem_tcldcc(void)
  25. {
  26. int tot = 0;
  27. struct portmap *pmap;
  28. for (pmap = root; pmap; pmap = pmap->next)
  29. tot += sizeof(struct portmap);
  30. return tot;
  31. }
  32. /***********************************************************************/
  33. static int tcl_putdcc STDVAR
  34. {
  35. int i, j;
  36. BADARGS(3, 3, " idx text");
  37. i = atoi(argv[1]);
  38. j = findidx(i);
  39. if (j < 0) {
  40. Tcl_AppendResult(irp, "invalid idx", NULL);
  41. return TCL_ERROR;
  42. }
  43. dumplots(-i, "", argv[2]);
  44. return TCL_OK;
  45. }
  46. /* Allows tcl scripts to send out raw data. Can be used for fast server
  47. * write (idx=0)
  48. *
  49. * usage:
  50. * putdccraw <idx> <size> <rawdata>
  51. * example:
  52. * putdccraw 6 13 "eggdrop rulz\n"
  53. *
  54. * (added by drummer@sophia.jpte.hu)
  55. */
  56. static int tcl_putdccraw STDVAR
  57. {
  58. int i, j = 0, z;
  59. BADARGS(4, 4, " idx size text");
  60. z = atoi(argv[1]);
  61. for (i = 0; i < dcc_total; i++) {
  62. if (!z && !strcmp(dcc[i].nick, "(server)")) {
  63. j = dcc[i].sock;
  64. break;
  65. } else if (dcc[i].sock == z) {
  66. j = dcc[i].sock;
  67. break;
  68. }
  69. }
  70. if (i == dcc_total) {
  71. Tcl_AppendResult(irp, "invalid idx", NULL);
  72. return TCL_ERROR;
  73. }
  74. tputs(j, argv[3], atoi(argv[2]));
  75. return TCL_OK;
  76. }
  77. static int tcl_dccsimul STDVAR
  78. {
  79. BADARGS(3, 3, " idx command");
  80. if (enable_simul) {
  81. int idx = findidx(atoi(argv[1]));
  82. if (idx >= 0 && (dcc[idx].type->flags & DCT_SIMUL)) {
  83. int l = strlen(argv[2]);
  84. if (l > 510) {
  85. l = 510;
  86. argv[2][510] = 0; /* Restrict length of cmd */
  87. }
  88. if (dcc[idx].type && dcc[idx].type->activity) {
  89. dcc[idx].type->activity(idx, argv[2], l);
  90. return TCL_OK;
  91. }
  92. } else
  93. Tcl_AppendResult(irp, "invalid idx", NULL);
  94. } else
  95. Tcl_AppendResult(irp, "simul disabled", NULL);
  96. return TCL_ERROR;
  97. }
  98. static int tcl_dccbroadcast STDVAR
  99. {
  100. char msg[sgrab-110];
  101. BADARGS(2, 2, " message");
  102. strncpyz(msg, argv[1], sizeof msg);
  103. chatout("*** %s\n", msg);
  104. botnet_send_chat(-1, botnetnick, msg);
  105. return TCL_OK;
  106. }
  107. static int tcl_hand2idx STDVAR
  108. {
  109. int i;
  110. char s[11];
  111. BADARGS(2, 2, " nickname");
  112. for (i = 0; i < dcc_total; i++)
  113. if ((dcc[i].type->flags & DCT_SIMUL) &&
  114. !egg_strcasecmp(argv[1], dcc[i].nick)) {
  115. egg_snprintf(s, sizeof s, "%ld", dcc[i].sock);
  116. Tcl_AppendResult(irp, s, NULL);
  117. return TCL_OK;
  118. }
  119. Tcl_AppendResult(irp, "-1", NULL);
  120. return TCL_OK;
  121. }
  122. static int tcl_getchan STDVAR
  123. {
  124. char s[7];
  125. int idx;
  126. BADARGS(2, 2, " idx");
  127. idx = findidx(atoi(argv[1]));
  128. if (idx < 0 ||
  129. (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
  130. Tcl_AppendResult(irp, "invalid idx", NULL);
  131. return TCL_ERROR;
  132. }
  133. if (dcc[idx].type == &DCC_SCRIPT)
  134. egg_snprintf(s, sizeof s, "%d", dcc[idx].u.script->u.chat->channel);
  135. else
  136. egg_snprintf(s, sizeof s, "%d", dcc[idx].u.chat->channel);
  137. Tcl_AppendResult(irp, s, NULL);
  138. return TCL_OK;
  139. }
  140. static int tcl_setchan STDVAR
  141. {
  142. int idx, chan;
  143. module_entry *me;
  144. BADARGS(3, 3, " idx channel");
  145. idx = findidx(atoi(argv[1]));
  146. if (idx < 0 ||
  147. (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
  148. Tcl_AppendResult(irp, "invalid idx", NULL);
  149. return TCL_ERROR;
  150. }
  151. if (argv[2][0] < '0' || argv[2][0] > '9') {
  152. if (!strcmp(argv[2], "-1") || !egg_strcasecmp(argv[2], "off"))
  153. chan = (-1);
  154. else {
  155. Tcl_SetVar(irp, "chan", argv[2], 0);
  156. if (Tcl_VarEval(irp, "assoc ", "$chan", NULL) != TCL_OK ||
  157. !interp->result[0]) {
  158. Tcl_AppendResult(irp, "channel name is invalid", NULL);
  159. return TCL_ERROR;
  160. }
  161. chan = atoi(interp->result);
  162. }
  163. } else
  164. chan = atoi(argv[2]);
  165. if ((chan < -1) || (chan > 199999)) {
  166. Tcl_AppendResult(irp, "channel out of range; must be -1 thru 199999",
  167. NULL);
  168. return TCL_ERROR;
  169. }
  170. if (dcc[idx].type == &DCC_SCRIPT)
  171. dcc[idx].u.script->u.chat->channel = chan;
  172. else {
  173. int oldchan = dcc[idx].u.chat->channel;
  174. if (dcc[idx].u.chat->channel >= 0) {
  175. if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS))
  176. botnet_send_part_idx(idx, "*script*");
  177. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  178. dcc[idx].u.chat->channel);
  179. }
  180. dcc[idx].u.chat->channel = chan;
  181. if (chan < GLOBAL_CHANS)
  182. botnet_send_join_idx(idx, oldchan);
  183. check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(idx),
  184. dcc[idx].sock, dcc[idx].host);
  185. }
  186. /* Console autosave. */
  187. if ((me = module_find("console", 0, 0))) {
  188. Function *func = me->funcs;
  189. (func[CONSOLE_DOSTORE]) (idx);
  190. }
  191. return TCL_OK;
  192. }
  193. static int tcl_dccputchan STDVAR
  194. {
  195. int chan;
  196. char msg[sgrab-110];
  197. BADARGS(3, 3, " channel message");
  198. chan = atoi(argv[1]);
  199. if ((chan < 0) || (chan > 199999)) {
  200. Tcl_AppendResult(irp, "channel out of range; must be 0 thru 199999",
  201. NULL);
  202. return TCL_ERROR;
  203. }
  204. strncpyz(msg, argv[2], sizeof msg);
  205. chanout_but(-1, chan, "*** %s\n", argv[2]);
  206. botnet_send_chan(-1, botnetnick, NULL, chan, argv[2]);
  207. check_tcl_bcst(botnetnick, chan, argv[2]);
  208. return TCL_OK;
  209. }
  210. static int tcl_console STDVAR
  211. {
  212. int i, j, pls, arg;
  213. module_entry *me;
  214. BADARGS(2, 4, " idx ?channel? ?console-modes?");
  215. i = findidx(atoi(argv[1]));
  216. if (i < 0 || dcc[i].type != &DCC_CHAT) {
  217. Tcl_AppendResult(irp, "invalid idx", NULL);
  218. return TCL_ERROR;
  219. }
  220. pls = 1;
  221. for (arg = 2; arg < argc; arg++) {
  222. if (argv[arg][0] && ((strchr(CHANMETA, argv[arg][0]) != NULL) ||
  223. (argv[arg][0] == '*'))) {
  224. if ((argv[arg][0] != '*') && (!findchan_by_dname(argv[arg]))) {
  225. /* If we dont find the channel, and it starts with a +... assume it
  226. * should be the console flags to set.
  227. */
  228. if (argv[arg][0]=='+')
  229. goto do_console_flags;
  230. Tcl_AppendResult(irp, "invalid channel", NULL);
  231. return TCL_ERROR;
  232. }
  233. strncpyz(dcc[i].u.chat->con_chan, argv[arg], 81);
  234. } else {
  235. if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
  236. dcc[i].u.chat->con_flags = 0;
  237. do_console_flags:
  238. for (j = 0; j < strlen(argv[arg]); j++) {
  239. if (argv[arg][j] == '+')
  240. pls = 1;
  241. else if (argv[arg][j] == '-')
  242. pls = (-1);
  243. else {
  244. char s[2];
  245. s[0] = argv[arg][j];
  246. s[1] = 0;
  247. if (pls == 1)
  248. dcc[i].u.chat->con_flags |= logmodes(s);
  249. else
  250. dcc[i].u.chat->con_flags &= ~logmodes(s);
  251. }
  252. }
  253. }
  254. }
  255. Tcl_AppendElement(irp, dcc[i].u.chat->con_chan);
  256. Tcl_AppendElement(irp, masktype(dcc[i].u.chat->con_flags));
  257. /* Console autosave. */
  258. if (argc > 2 && (me = module_find("console", 0, 0))) {
  259. Function *func = me->funcs;
  260. (func[CONSOLE_DOSTORE]) (i);
  261. }
  262. return TCL_OK;
  263. }
  264. static int tcl_strip STDVAR
  265. {
  266. int i, j, pls, arg;
  267. module_entry *me;
  268. BADARGS(2, 4, " idx ?strip-flags?");
  269. i = findidx(atoi(argv[1]));
  270. if (i < 0 || dcc[i].type != &DCC_CHAT) {
  271. Tcl_AppendResult(irp, "invalid idx", NULL);
  272. return TCL_ERROR;
  273. }
  274. pls = 1;
  275. for (arg = 2; arg < argc; arg++) {
  276. if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
  277. dcc[i].u.chat->strip_flags = 0;
  278. for (j = 0; j < strlen(argv[arg]); j++) {
  279. if (argv[arg][j] == '+')
  280. pls = 1;
  281. else if (argv[arg][j] == '-')
  282. pls = (-1);
  283. else {
  284. char s[2];
  285. s[0] = argv[arg][j];
  286. s[1] = 0;
  287. if (pls == 1)
  288. dcc[i].u.chat->strip_flags |= stripmodes(s);
  289. else
  290. dcc[i].u.chat->strip_flags &= ~stripmodes(s);
  291. }
  292. }
  293. }
  294. Tcl_AppendElement(irp, stripmasktype(dcc[i].u.chat->strip_flags));
  295. /* Console autosave. */
  296. if (argc > 2 && (me = module_find("console", 0, 0))) {
  297. Function *func = me->funcs;
  298. (func[CONSOLE_DOSTORE]) (i);
  299. }
  300. return TCL_OK;
  301. }
  302. static int tcl_echo STDVAR
  303. {
  304. int i;
  305. module_entry *me;
  306. BADARGS(2, 3, " idx ?status?");
  307. i = findidx(atoi(argv[1]));
  308. if (i < 0 || dcc[i].type != &DCC_CHAT) {
  309. Tcl_AppendResult(irp, "invalid idx", NULL);
  310. return TCL_ERROR;
  311. }
  312. if (argc == 3) {
  313. if (atoi(argv[2]))
  314. dcc[i].status |= STAT_ECHO;
  315. else
  316. dcc[i].status &= ~STAT_ECHO;
  317. }
  318. if (dcc[i].status & STAT_ECHO)
  319. Tcl_AppendResult(irp, "1", NULL);
  320. else
  321. Tcl_AppendResult(irp, "0", NULL);
  322. /* Console autosave. */
  323. if (argc > 2 && (me = module_find("console", 0, 0))) {
  324. Function *func = me->funcs;
  325. (func[CONSOLE_DOSTORE]) (i);
  326. }
  327. return TCL_OK;
  328. }
  329. static int tcl_page STDVAR
  330. {
  331. int i;
  332. char x[20];
  333. module_entry *me;
  334. BADARGS(2, 3, " idx ?status?");
  335. i = findidx(atoi(argv[1]));
  336. if (i < 0 || dcc[i].type != &DCC_CHAT) {
  337. Tcl_AppendResult(irp, "invalid idx", NULL);
  338. return TCL_ERROR;
  339. }
  340. if (argc == 3) {
  341. int l = atoi(argv[2]);
  342. if (!l)
  343. dcc[i].status &= ~STAT_PAGE;
  344. else {
  345. dcc[i].status |= STAT_PAGE;
  346. dcc[i].u.chat->max_line = l;
  347. }
  348. }
  349. if (dcc[i].status & STAT_PAGE) {
  350. egg_snprintf(x, sizeof x, "%d", dcc[i].u.chat->max_line);
  351. Tcl_AppendResult(irp, x, NULL);
  352. } else
  353. Tcl_AppendResult(irp, "0", NULL);
  354. /* Console autosave. */
  355. if ((argc > 2) && (me = module_find("console", 0, 0))) {
  356. Function *func = me->funcs;
  357. (func[CONSOLE_DOSTORE]) (i);
  358. }
  359. return TCL_OK;
  360. }
  361. static int tcl_control STDVAR
  362. {
  363. int idx;
  364. void *hold;
  365. BADARGS(3, 3, " idx command");
  366. idx = findidx(atoi(argv[1]));
  367. if (idx < 0) {
  368. Tcl_AppendResult(irp, "invalid idx", NULL);
  369. return TCL_ERROR;
  370. }
  371. if (dcc[idx].type->flags & DCT_CHAT) {
  372. if (dcc[idx].u.chat->channel >= 0) {
  373. chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has gone.\n",
  374. dcc[idx].nick);
  375. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  376. dcc[idx].u.chat->channel);
  377. botnet_send_part_idx(idx, "gone");
  378. }
  379. check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
  380. }
  381. hold = dcc[idx].u.other;
  382. dcc[idx].u.script = get_data_ptr(sizeof(struct script_info));
  383. dcc[idx].u.script->u.other = hold;
  384. dcc[idx].u.script->type = dcc[idx].type;
  385. dcc[idx].type = &DCC_SCRIPT;
  386. /* Do not buffer data anymore. All received and stored data is passed
  387. over to the dcc functions from now on. */
  388. sockoptions(dcc[idx].sock, EGG_OPTION_UNSET, SOCK_BUFFER);
  389. strncpyz(dcc[idx].u.script->command, argv[2], 120);
  390. return TCL_OK;
  391. }
  392. static int tcl_valididx STDVAR
  393. {
  394. int idx;
  395. BADARGS(2, 2, " idx");
  396. idx = findidx(atoi(argv[1]));
  397. if (idx < 0 || !(dcc[idx].type->flags & DCT_VALIDIDX))
  398. Tcl_AppendResult(irp, "0", NULL);
  399. else
  400. Tcl_AppendResult(irp, "1", NULL);
  401. return TCL_OK;
  402. }
  403. static int tcl_killdcc STDVAR
  404. {
  405. int idx;
  406. BADARGS(2, 3, " idx ?reason?");
  407. idx = findidx(atoi(argv[1]));
  408. if (idx < 0) {
  409. Tcl_AppendResult(irp, "invalid idx", NULL);
  410. return TCL_ERROR;
  411. }
  412. /* Don't kill terminal socket */
  413. if ((dcc[idx].sock == STDOUT) && !backgrd)
  414. return TCL_OK;
  415. /* Make sure 'whom' info is updated for other bots */
  416. if (dcc[idx].type->flags & DCT_CHAT) {
  417. chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has left the %s%s%s\n",
  418. dcc[idx].nick, dcc[idx].u.chat ? "channel" : "partyline",
  419. argc == 3 ? ": " : "", argc == 3 ? argv[2] : "");
  420. botnet_send_part_idx(idx, argc == 3 ? argv[2] : "");
  421. if ((dcc[idx].u.chat->channel >= 0) &&
  422. (dcc[idx].u.chat->channel < GLOBAL_CHANS))
  423. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  424. dcc[idx].u.chat->channel);
  425. check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
  426. /* Notice is sent to the party line, the script can add a reason. */
  427. }
  428. killsock(dcc[idx].sock);
  429. lostdcc(idx);
  430. return TCL_OK;
  431. }
  432. static int tcl_putbot STDVAR
  433. {
  434. int i;
  435. char msg[sgrab-110];
  436. BADARGS(3, 3, " botnick message");
  437. i = nextbot(argv[1]);
  438. if (i < 0) {
  439. Tcl_AppendResult(irp, "bot is not in the botnet", NULL);
  440. return TCL_ERROR;
  441. }
  442. strncpyz(msg, argv[2], sizeof msg);
  443. botnet_send_zapf(i, botnetnick, argv[1], msg);
  444. return TCL_OK;
  445. }
  446. static int tcl_putallbots STDVAR
  447. {
  448. char msg[sgrab-110];
  449. BADARGS(2, 2, " message");
  450. strncpyz(msg, argv[1], sizeof msg);
  451. botnet_send_zapf_broad(-1, botnetnick, NULL, msg);
  452. return TCL_OK;
  453. }
  454. static int tcl_idx2hand STDVAR
  455. {
  456. int idx;
  457. BADARGS(2, 2, " idx");
  458. idx = findidx(atoi(argv[1]));
  459. if (idx < 0) {
  460. Tcl_AppendResult(irp, "invalid idx", NULL);
  461. return TCL_ERROR;
  462. }
  463. Tcl_AppendResult(irp, dcc[idx].nick, NULL);
  464. return TCL_OK;
  465. }
  466. static int tcl_islinked STDVAR
  467. {
  468. int i;
  469. BADARGS(2, 2, " bot");
  470. i = nextbot(argv[1]);
  471. if (i < 0)
  472. Tcl_AppendResult(irp, "0", NULL);
  473. else
  474. Tcl_AppendResult(irp, "1", NULL);
  475. return TCL_OK;
  476. }
  477. static int tcl_randstring STDVAR
  478. {
  479. int length = atoi(argv[1]);
  480. char s[length+1];
  481. BADARGS(2, 2, " length");
  482. if (length) {
  483. make_rand_str(s,length);
  484. Tcl_AppendResult(irp, s, NULL);
  485. } else
  486. Tcl_AppendResult(irp, "", NULL);
  487. return TCL_OK;
  488. }
  489. //This function is simply for the tcl to check if the right binary is being used.
  490. static int tcl_hcheck STDVAR
  491. {
  492. Tcl_AppendResult(irp, "1", NULL);
  493. return TCL_OK;
  494. }
  495. static int tcl_binname STDVAR
  496. {
  497. Tcl_AppendResult(irp, binname, NULL);
  498. return TCL_OK;
  499. }
  500. static int tcl_configend STDVAR
  501. {
  502. Tcl_AppendResult(irp, "1", NULL);
  503. return TCL_OK;
  504. }
  505. static int tcl_esource STDVAR
  506. {
  507. int code, nc, skip = 0, incom = 0, lines = 0, line = 0;
  508. FILE *f;
  509. char *buf, *tptr, templine[2048];
  510. char *temps = NULL, temps2[2048];
  511. char *horeting, check[2048];
  512. struct stat st;
  513. BADARGS(2, 2, " file");
  514. /* Check whether file is readable. */
  515. if ((f = fopen(argv[1], "r")) == NULL)
  516. return 0;
  517. fclose(f);
  518. if (stat(argv[1], &st)) {
  519. fatal("broken file", 0);
  520. }
  521. buf = nmalloc(st.st_size * 2.5);
  522. *buf = 0;
  523. f = fopen(argv[1], "r");
  524. if (!f)
  525. fatal("broken file", 0);
  526. while(fgets(templine, sizeof(templine), f)) {
  527. nc = 0;
  528. if(strchr(templine, '\n')) {
  529. tptr = templine;
  530. while( (tptr = strchr(tptr, '\n')) ) {
  531. nc++;
  532. *tptr++ = 0;
  533. }
  534. }
  535. horeting = decryptit(templine);
  536. temps = (char *) decrypt_string(netpass, horeting);
  537. temps2[0] = '\0';
  538. strcpy(temps2,temps);
  539. nfree(temps);
  540. strcpy(check,temps2);
  541. line++;
  542. if (!strncmp(check,"-ifhub",6) || !strncmp(check,"-ifleaf",7) || !strncmp(check,"-endif",6) || (!strncmp(check,"-else",5) && (skip == 1 || skip == 2)) || !strncmp(check,"/*",2) || !strncmp(check,"*/",2) || !strcmp(check+(strlen(check)-2),"*/") || !strncmp(check,"//",2)) {
  543. /* skip == 1 means hub code is being processed, 2 is leaf code */
  544. if (!strncmp(check,"-",1) && !incom) { //check for changing defines, but not if in comment.
  545. if (!strncmp(check,"-ifhub",6))
  546. skip = 1;
  547. else if (!strncmp(check,"-ifleaf",7))
  548. skip = 2;
  549. else if (!strncmp(check,"-endif",6)) { //end the ifdef
  550. if (skip)
  551. skip = 0;
  552. else {
  553. putlog(LOG_MISC, "*", "Error on line %i -endif with no ifdef!", line);
  554. return 0;
  555. }
  556. }
  557. else if (!strncmp(check,"-else",5)) { //change the ifdef from hub->leaf or leaf->hub
  558. if (skip == 1)
  559. skip = 2;
  560. else if (skip == 2)
  561. skip = 1;
  562. else {
  563. putlog(LOG_MISC, "*", "Error on line %i -else with no ifdef!", line);
  564. return 0;
  565. }
  566. }
  567. }
  568. else { //then it must be a comment!
  569. if (!strncmp(check,"/*",2))
  570. if (!incom)
  571. incom = 1;
  572. else {
  573. putlog(LOG_MISC, "*", "Error on line %i New /* inside a /*", line);
  574. return 0;
  575. }
  576. else if (!strcmp(check+(strlen(check)-2),"*/") || !strncmp(check,"*/",2)) {
  577. if (incom)
  578. incom = 0;
  579. else {
  580. putlog(LOG_MISC, "*", "Error on line %i */ without a /*", line);
  581. return 0;
  582. }
  583. }
  584. //we dont need to check for // because its a 1 line skip, the actual read is an ELSE.
  585. }
  586. check[0] = '\0';
  587. }
  588. else {
  589. if ((((hub && (skip == 1)) || (leaf && (skip == 2))) || (!skip)) && !incom) {
  590. lines++;
  591. strcat(buf, temps2);
  592. while (nc > 0) {
  593. strcat(buf, "\n");
  594. nc--;
  595. }
  596. }
  597. }
  598. }
  599. // putlog(LOG_MISC, "@", "Loading %i lines from tcl", lines);
  600. code = Tcl_Eval(interp, buf);
  601. memset(buf, 0, st.st_size*2.5);
  602. nfree(buf);
  603. return code;
  604. }
  605. static int tcl_bots STDVAR
  606. {
  607. tand_t *bot;
  608. BADARGS(1, 1, "");
  609. for (bot = tandbot; bot; bot = bot->next)
  610. Tcl_AppendElement(irp, bot->bot);
  611. return TCL_OK;
  612. }
  613. static int tcl_botlist STDVAR
  614. {
  615. tand_t *bot;
  616. char *p;
  617. char sh[2], string[20];
  618. #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
  619. CONST char *list[4];
  620. #else
  621. char *list[4];
  622. #endif
  623. BADARGS(1, 1, "");
  624. sh[1] = 0;
  625. list[3] = sh;
  626. list[2] = string;
  627. for (bot = tandbot; bot; bot = bot->next) {
  628. list[0] = bot->bot;
  629. list[1] = (bot->uplink == (tand_t *) 1) ? botnetnick : bot->uplink->bot;
  630. strncpyz(string, int_to_base10(bot->ver), sizeof string);
  631. sh[0] = bot->share;
  632. p = Tcl_Merge(4, list);
  633. Tcl_AppendElement(irp, p);
  634. Tcl_Free((char *) p);
  635. }
  636. return TCL_OK;
  637. }
  638. /* list of { idx nick host type {other} timestamp}
  639. */
  640. static int tcl_dcclist STDVAR
  641. {
  642. int i;
  643. char idxstr[10];
  644. char timestamp[11];
  645. char *p;
  646. char other[160];
  647. #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
  648. CONST char *list[6];
  649. #else
  650. char *list[6];
  651. #endif
  652. BADARGS(1, 2, " ?type?");
  653. for (i = 0; i < dcc_total; i++) {
  654. if (argc == 1 ||
  655. ((argc == 2) && (dcc[i].type && !egg_strcasecmp(dcc[i].type->name, argv[1])))) {
  656. egg_snprintf(idxstr, sizeof idxstr, "%ld", dcc[i].sock);
  657. egg_snprintf(timestamp, sizeof timestamp, "%ld", dcc[i].timeval);
  658. if (dcc[i].type && dcc[i].type->display)
  659. dcc[i].type->display(i, other);
  660. else {
  661. egg_snprintf(other, sizeof other, "?:%lX !! ERROR !!",
  662. (long) dcc[i].type);
  663. break;
  664. }
  665. list[0] = idxstr;
  666. list[1] = dcc[i].nick;
  667. list[2] = dcc[i].host;
  668. list[3] = dcc[i].type ? dcc[i].type->name : "*UNKNOWN*";
  669. list[4] = other;
  670. list[5] = timestamp;
  671. p = Tcl_Merge(6, list);
  672. Tcl_AppendElement(irp, p);
  673. Tcl_Free((char *) p);
  674. }
  675. }
  676. return TCL_OK;
  677. }
  678. /* list of { nick bot host flag idletime awaymsg [channel]}
  679. */
  680. static int tcl_whom STDVAR
  681. {
  682. char c[2], idle[11], work[20], *p;
  683. int chan, i;
  684. #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
  685. CONST char *list[7];
  686. #else
  687. char *list[7];
  688. #endif
  689. BADARGS(2, 2, " chan");
  690. if (argv[1][0] == '*')
  691. chan = -1;
  692. else {
  693. if ((argv[1][0] < '0') || (argv[1][0] > '9')) {
  694. Tcl_SetVar(interp, "chan", argv[1], 0);
  695. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) != TCL_OK) ||
  696. !interp->result[0]) {
  697. Tcl_AppendResult(irp, "channel name is invalid", NULL);
  698. return TCL_ERROR;
  699. }
  700. chan = atoi(interp->result);
  701. } else
  702. chan = atoi(argv[1]);
  703. if ((chan < 0) || (chan > 199999)) {
  704. Tcl_AppendResult(irp, "channel out of range; must be 0 thru 199999",
  705. NULL);
  706. return TCL_ERROR;
  707. }
  708. }
  709. for (i = 0; i < dcc_total; i++)
  710. if (dcc[i].type == &DCC_CHAT) {
  711. if (dcc[i].u.chat->channel == chan || chan == -1) {
  712. c[0] = geticon(i);
  713. c[1] = 0;
  714. egg_snprintf(idle, sizeof idle, "%lu", (now - dcc[i].timeval) / 60);
  715. list[0] = dcc[i].nick;
  716. list[1] = botnetnick;
  717. list[2] = dcc[i].host;
  718. list[3] = c;
  719. list[4] = idle;
  720. list[5] = dcc[i].u.chat->away ? dcc[i].u.chat->away : "";
  721. if (chan == -1) {
  722. egg_snprintf(work, sizeof work, "%d", dcc[i].u.chat->channel);
  723. list[6] = work;
  724. }
  725. p = Tcl_Merge((chan == -1) ? 7 : 6, list);
  726. Tcl_AppendElement(irp, p);
  727. Tcl_Free((char *) p);
  728. }
  729. }
  730. for (i = 0; i < parties; i++) {
  731. if (party[i].chan == chan || chan == -1) {
  732. c[0] = party[i].flag;
  733. c[1] = 0;
  734. if (party[i].timer == 0L)
  735. strcpy(idle, "0");
  736. else
  737. egg_snprintf(idle, sizeof idle, "%lu", (now - party[i].timer) / 60);
  738. list[0] = party[i].nick;
  739. list[1] = party[i].bot;
  740. list[2] = party[i].from ? party[i].from : "";
  741. list[3] = c;
  742. list[4] = idle;
  743. list[5] = party[i].status & PLSTAT_AWAY ? party[i].away : "";
  744. if (chan == -1) {
  745. egg_snprintf(work, sizeof work, "%d", party[i].chan);
  746. list[6] = work;
  747. }
  748. p = Tcl_Merge((chan == -1) ? 7 : 6, list);
  749. Tcl_AppendElement(irp, p);
  750. Tcl_Free((char *) p);
  751. }
  752. }
  753. return TCL_OK;
  754. }
  755. static int tcl_dccused STDVAR
  756. {
  757. char s[20];
  758. BADARGS(1, 1, "");
  759. egg_snprintf(s, sizeof s, "%d", dcc_total);
  760. Tcl_AppendResult(irp, s, NULL);
  761. return TCL_OK;
  762. }
  763. static int tcl_getdccidle STDVAR
  764. {
  765. int x, idx;
  766. char s[21];
  767. BADARGS(2, 2, " idx");
  768. idx = findidx(atoi(argv[1]));
  769. if (idx < 0) {
  770. Tcl_AppendResult(irp, "invalid idx", NULL);
  771. return TCL_ERROR;
  772. }
  773. x = (now - dcc[idx].timeval);
  774. egg_snprintf(s, sizeof s, "%d", x);
  775. Tcl_AppendElement(irp, s);
  776. return TCL_OK;
  777. }
  778. static int tcl_getdccaway STDVAR
  779. {
  780. int idx;
  781. BADARGS(2, 2, " idx");
  782. idx = findidx(atol(argv[1]));
  783. if (idx < 0 || dcc[idx].type != &DCC_CHAT) {
  784. Tcl_AppendResult(irp, "invalid idx", NULL);
  785. return TCL_ERROR;
  786. }
  787. if (dcc[idx].u.chat->away == NULL)
  788. return TCL_OK;
  789. Tcl_AppendResult(irp, dcc[idx].u.chat->away, NULL);
  790. return TCL_OK;
  791. }
  792. static int tcl_setdccaway STDVAR
  793. {
  794. int idx;
  795. BADARGS(3, 3, " idx message");
  796. idx = findidx(atol(argv[1]));
  797. if (idx < 0 || dcc[idx].type != &DCC_CHAT) {
  798. Tcl_AppendResult(irp, "invalid idx", NULL);
  799. return TCL_ERROR;
  800. }
  801. if (!argv[2][0]) {
  802. /* un-away */
  803. if (dcc[idx].u.chat->away != NULL)
  804. not_away(idx);
  805. return TCL_OK;
  806. }
  807. /* away */
  808. set_away(idx, argv[2]);
  809. return TCL_OK;
  810. }
  811. static int tcl_link STDVAR
  812. {
  813. int x, i;
  814. char bot[HANDLEN + 1], bot2[HANDLEN + 1];
  815. BADARGS(2, 3, " ?via-bot? bot");
  816. strncpyz(bot, argv[1], sizeof bot);
  817. if (argc == 3) {
  818. x = 1;
  819. strncpyz(bot2, argv[2], sizeof bot2);
  820. i = nextbot(bot);
  821. if (i < 0)
  822. x = 0;
  823. else
  824. botnet_send_link(i, botnetnick, bot, bot2);
  825. } else
  826. x = botlink("", -2, bot);
  827. egg_snprintf(bot, sizeof bot, "%d", x);
  828. Tcl_AppendResult(irp, bot, NULL);
  829. return TCL_OK;
  830. }
  831. static int tcl_unlink STDVAR
  832. {
  833. int i, x;
  834. char bot[HANDLEN + 1];
  835. BADARGS(2, 3, " bot ?comment?");
  836. strncpyz(bot, argv[1], sizeof bot);
  837. i = nextbot(bot);
  838. if (i < 0)
  839. x = 0;
  840. else {
  841. x = 1;
  842. if (!egg_strcasecmp(bot, dcc[i].nick))
  843. x = botunlink(-2, bot, argv[2]);
  844. else
  845. botnet_send_unlink(i, botnetnick, lastbot(bot), bot, argv[2]);
  846. }
  847. egg_snprintf(bot, sizeof bot, "%d", x);
  848. Tcl_AppendResult(irp, bot, NULL);
  849. return TCL_OK;
  850. }
  851. static int tcl_connect STDVAR
  852. {
  853. int i, z, sock;
  854. char s[81];
  855. BADARGS(3, 3, " hostname port");
  856. if (dcc_total == max_dcc) {
  857. Tcl_AppendResult(irp, "out of dcc table space", NULL);
  858. return TCL_ERROR;
  859. }
  860. #ifdef USE_IPV6
  861. sock = getsock(0, hostprotocol(argv[1]));
  862. #else
  863. sock = getsock(0);
  864. #endif /* USE_IPV6 */
  865. if (sock < 0) {
  866. Tcl_AppendResult(irp, MISC_NOFREESOCK, NULL);
  867. return TCL_ERROR;
  868. }
  869. z = open_telnet_raw(sock, argv[1], atoi(argv[2]));
  870. if (z < 0) {
  871. killsock(sock);
  872. if (z == (-2))
  873. strncpyz(s, "DNS lookup failed", sizeof s);
  874. else
  875. neterror(s);
  876. Tcl_AppendResult(irp, s, NULL);
  877. return TCL_ERROR;
  878. }
  879. /* Well well well... it worked! */
  880. i = new_dcc(&DCC_SOCKET, 0);
  881. dcc[i].sock = sock;
  882. dcc[i].port = atoi(argv[2]);
  883. strcpy(dcc[i].nick, "*");
  884. strncpyz(dcc[i].host, argv[1], UHOSTMAX);
  885. egg_snprintf(s, sizeof s, "%d", sock);
  886. Tcl_AppendResult(irp, s, NULL);
  887. return TCL_OK;
  888. }
  889. /* Create a new listening port (or destroy one)
  890. *
  891. * listen <port> bots/all/users [mask]
  892. * listen <port> script <proc> [flag]
  893. * listen <port> off
  894. */
  895. static int tcl_listen STDVAR
  896. {
  897. int i, j, idx = (-1), port, realport;
  898. char s[11];
  899. struct portmap *pmap = NULL, *pold = NULL;
  900. BADARGS(3, 5, " port type ?mask?/?proc ?flag??");
  901. port = realport = atoi(argv[1]);
  902. for (pmap = root; pmap; pold = pmap, pmap = pmap->next)
  903. if (pmap->realport == port) {
  904. port = pmap->mappedto;
  905. break;
  906. }
  907. for (i = 0; i < dcc_total; i++)
  908. if ((dcc[i].type == &DCC_TELNET) && (dcc[i].port == port))
  909. idx = i;
  910. if (!egg_strcasecmp(argv[2], "off")) {
  911. if (pmap) {
  912. if (pold)
  913. pold->next = pmap->next;
  914. else
  915. root = pmap->next;
  916. nfree(pmap);
  917. }
  918. /* Remove */
  919. if (idx < 0) {
  920. Tcl_AppendResult(irp, "no such listen port is open", NULL);
  921. return TCL_ERROR;
  922. }
  923. killsock(dcc[idx].sock);
  924. lostdcc(idx);
  925. return TCL_OK;
  926. }
  927. if (idx < 0) {
  928. /* Make new one */
  929. if (dcc_total >= max_dcc) {
  930. Tcl_AppendResult(irp, "no more DCC slots available", NULL);
  931. return TCL_ERROR;
  932. }
  933. cache_my_ip(); /* may need to do this because config loads before ip's are cached -bryan */
  934. /* Try to grab port */
  935. j = port + 20;
  936. i = (-1);
  937. while (port < j && i < 0) {
  938. #ifdef USE_IPV6
  939. /* dum de dum, listen needs an af_def option, on linux this will listen on
  940. * both ipv6 and ipv4
  941. */
  942. i = open_listen_by_af(&port, AF_INET6);
  943. #else
  944. i = open_listen(&port);
  945. #endif /* USE_IPV6 */
  946. if (i == -1)
  947. port++;
  948. else if (i == -2)
  949. break;
  950. }
  951. if (i == -1) {
  952. Tcl_AppendResult(irp, "Couldn't grab nearby port", NULL);
  953. return TCL_ERROR;
  954. } else if (i == -2) {
  955. Tcl_AppendResult(irp, "Couldn't assign the requested IP. Please make sure 'my-ip' is set properly.", NULL);
  956. return TCL_ERROR;
  957. }
  958. idx = new_dcc(&DCC_TELNET, 0);
  959. dcc[idx].addr = iptolong(getmyip());
  960. dcc[idx].port = port;
  961. dcc[idx].sock = i;
  962. dcc[idx].timeval = now;
  963. }
  964. /* script? */
  965. if (!strcmp(argv[2], "script")) {
  966. strcpy(dcc[idx].nick, "(script)");
  967. if (argc < 4) {
  968. Tcl_AppendResult(irp, "must give proc name for script listen", NULL);
  969. killsock(dcc[idx].sock);
  970. lostdcc(idx);
  971. return TCL_ERROR;
  972. }
  973. if (argc == 5) {
  974. if (strcmp(argv[4], "pub")) {
  975. Tcl_AppendResult(irp, "unknown flag: ", argv[4], ". allowed flags: pub",
  976. NULL);
  977. killsock(dcc[idx].sock);
  978. lostdcc(idx);
  979. return TCL_ERROR;
  980. }
  981. dcc[idx].status = LSTN_PUBLIC;
  982. }
  983. strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
  984. egg_snprintf(s, sizeof s, "%d", port);
  985. Tcl_AppendResult(irp, s, NULL);
  986. return TCL_OK;
  987. }
  988. /* bots/users/all */
  989. if (!strcmp(argv[2], "bots"))
  990. strcpy(dcc[idx].nick, "(bots)");
  991. else if (!strcmp(argv[2], "users"))
  992. strcpy(dcc[idx].nick, "(users)");
  993. else if (!strcmp(argv[2], "all"))
  994. strcpy(dcc[idx].nick, "(telnet)");
  995. if (!dcc[idx].nick[0]) {
  996. Tcl_AppendResult(irp, "illegal listen type: must be one of ",
  997. "bots, users, all, off, script", NULL);
  998. killsock(dcc[idx].sock);
  999. dcc_total--;
  1000. return TCL_ERROR;
  1001. }
  1002. if (argc == 4) {
  1003. strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
  1004. } else
  1005. strcpy(dcc[idx].host, "*");
  1006. egg_snprintf(s, sizeof s, "%d", port);
  1007. Tcl_AppendResult(irp, s, NULL);
  1008. if (!pmap) {
  1009. pmap = nmalloc(sizeof(struct portmap));
  1010. pmap->next = root;
  1011. root = pmap;
  1012. }
  1013. pmap->realport = realport;
  1014. pmap->mappedto = port;
  1015. putlog(LOG_MISC, "*", "Listening at telnet port %d (%s)", port, argv[2]);
  1016. return TCL_OK;
  1017. }
  1018. static int tcl_boot STDVAR
  1019. {
  1020. char who[NOTENAMELEN + 1];
  1021. int i, ok = 0;
  1022. BADARGS(2, 3, " user@bot ?reason?");
  1023. strncpyz(who, argv[1], sizeof who);
  1024. if (strchr(who, '@') != NULL) {
  1025. char whonick[HANDLEN + 1];
  1026. splitc(whonick, who, '@');
  1027. whonick[HANDLEN] = 0;
  1028. if (!egg_strcasecmp(who, botnetnick))
  1029. strncpyz(who, whonick, sizeof who);
  1030. else if (remote_boots > 0) {
  1031. i = nextbot(who);
  1032. if (i < 0)
  1033. return TCL_OK;
  1034. botnet_send_reject(i, botnetnick, NULL, whonick, who, argv[2] ? argv[2] : "");
  1035. } else {
  1036. return TCL_OK;
  1037. }
  1038. }
  1039. for (i = 0; i < dcc_total; i++)
  1040. if (!ok && (dcc[i].type->flags & DCT_CANBOOT) &&
  1041. !egg_strcasecmp(dcc[i].nick, who)) {
  1042. do_boot(i, botnetnick, argv[2] ? argv[2] : "");
  1043. ok = 1;
  1044. }
  1045. return TCL_OK;
  1046. }
  1047. static int tcl_rehash STDVAR
  1048. {
  1049. BADARGS(1, 1, " ");
  1050. #ifdef HUB
  1051. write_userfile(-1);
  1052. #endif
  1053. putlog(LOG_MISC, "*", USERF_REHASHING);
  1054. do_restart = -2;
  1055. return TCL_OK;
  1056. }
  1057. static int tcl_restart STDVAR
  1058. {
  1059. BADARGS(1, 1, " ");
  1060. if (!backgrd) {
  1061. Tcl_AppendResult(interp, "You can't restart a -n bot", NULL);
  1062. return TCL_ERROR;
  1063. }
  1064. #ifdef HUB
  1065. write_userfile(-1);
  1066. #endif
  1067. putlog(LOG_MISC, "*", MISC_RESTARTING);
  1068. wipe_timers(interp, &utimer);
  1069. wipe_timers(interp, &timer);
  1070. do_restart = -1;
  1071. return TCL_OK;
  1072. }
  1073. static int tcl_traffic STDVAR
  1074. {
  1075. char buf[1024];
  1076. unsigned long out_total_today, out_total;
  1077. unsigned long in_total_today, in_total;
  1078. /* IRC traffic */
  1079. sprintf(buf, "irc %ld %ld %ld %ld", itraffic_irc_today, itraffic_irc +
  1080. itraffic_irc_today, otraffic_irc_today, otraffic_irc + otraffic_irc_today);
  1081. Tcl_AppendElement(irp, buf);
  1082. /* Botnet traffic */
  1083. sprintf(buf, "botnet %ld %ld %ld %ld", itraffic_bn_today, itraffic_bn +
  1084. itraffic_bn_today, otraffic_bn_today, otraffic_bn + otraffic_bn_today);
  1085. Tcl_AppendElement(irp, buf);
  1086. /* Partyline */
  1087. sprintf(buf, "partyline %ld %ld %ld %ld", itraffic_dcc_today, itraffic_dcc +
  1088. itraffic_dcc_today, otraffic_dcc_today, otraffic_dcc + otraffic_dcc_today);
  1089. Tcl_AppendElement(irp, buf);
  1090. /* Transfer */
  1091. sprintf(buf, "transfer %ld %ld %ld %ld", itraffic_trans_today, itraffic_trans +
  1092. itraffic_trans_today, otraffic_trans_today, otraffic_trans + otraffic_trans_today);
  1093. Tcl_AppendElement(irp, buf);
  1094. /* Misc traffic */
  1095. sprintf(buf, "misc %ld %ld %ld %ld", itraffic_unknown_today, itraffic_unknown +
  1096. itraffic_unknown_today, otraffic_unknown_today, otraffic_unknown +
  1097. otraffic_unknown_today);
  1098. Tcl_AppendElement(irp, buf);
  1099. /* Totals */
  1100. in_total_today = itraffic_irc_today + itraffic_bn_today + itraffic_dcc_today +
  1101. itraffic_trans_today + itraffic_unknown_today,
  1102. in_total = in_total_today + itraffic_irc + itraffic_bn + itraffic_dcc +
  1103. itraffic_trans + itraffic_unknown;
  1104. out_total_today = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today +
  1105. itraffic_trans_today + otraffic_unknown_today,
  1106. out_total = out_total_today + otraffic_irc + otraffic_bn + otraffic_dcc +
  1107. otraffic_trans + otraffic_unknown;
  1108. sprintf(buf, "total %ld %ld %ld %ld", in_total_today, in_total, out_total_today, out_total);
  1109. Tcl_AppendElement(irp, buf);
  1110. return(TCL_OK);
  1111. }
  1112. tcl_cmds tcldcc_cmds[] =
  1113. {
  1114. {"binname", tcl_binname},
  1115. {"putdcc", tcl_putdcc},
  1116. {"putdccraw", tcl_putdccraw},
  1117. {"putidx", tcl_putdcc},
  1118. {"dccsimul", tcl_dccsimul},
  1119. {"dccbroadcast", tcl_dccbroadcast},
  1120. {"hand2idx", tcl_hand2idx},
  1121. {"getchan", tcl_getchan},
  1122. {"setchan", tcl_setchan},
  1123. {"dccputchan", tcl_dccputchan},
  1124. {"console", tcl_console},
  1125. {"strip", tcl_strip},
  1126. {"echo", tcl_echo},
  1127. {"page", tcl_page},
  1128. {"control", tcl_control},
  1129. {"valididx", tcl_valididx},
  1130. {"killdcc", tcl_killdcc},
  1131. {"putbot", tcl_putbot},
  1132. {"putallbots", tcl_putallbots},
  1133. {"idx2hand", tcl_idx2hand},
  1134. {"bots", tcl_bots},
  1135. {"botlist", tcl_botlist},
  1136. {"dcclist", tcl_dcclist},
  1137. {"whom", tcl_whom},
  1138. {"dccused", tcl_dccused},
  1139. {"getdccidle", tcl_getdccidle},
  1140. {"getdccaway", tcl_getdccaway},
  1141. {"setdccaway", tcl_setdccaway},
  1142. {"islinked", tcl_islinked},
  1143. {"hcheck", tcl_hcheck},
  1144. {"randstring", tcl_randstring},
  1145. {"source", tcl_esource},
  1146. {"config_end", tcl_configend},
  1147. {"link", tcl_link},
  1148. {"unlink", tcl_unlink},
  1149. {"connect", tcl_connect},
  1150. {"listen", tcl_listen},
  1151. {"boot", tcl_boot},
  1152. {"rehash", tcl_rehash},
  1153. {"restart", tcl_restart},
  1154. {"traffic", tcl_traffic},
  1155. {NULL, NULL}
  1156. };