00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "main.h"
00027 #include "tandem.h"
00028 #include "modules.h"
00029
00030 extern Tcl_Interp *interp;
00031 extern tcl_timer_t *timer, *utimer;
00032 extern struct dcc_t *dcc;
00033 extern char botnetnick[];
00034 extern int dcc_total, backgrd, parties, make_userfile, do_restart, remote_boots, max_dcc;
00035 extern party_t *party;
00036 extern tand_t *tandbot;
00037 extern time_t now;
00038 extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc,
00039 itraffic_irc_today, otraffic_bn, otraffic_bn_today,
00040 itraffic_bn, itraffic_bn_today, otraffic_dcc,
00041 otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today,
00042 otraffic_trans, otraffic_trans_today, itraffic_trans,
00043 itraffic_trans_today, otraffic_unknown, itraffic_unknown,
00044 otraffic_unknown_today, itraffic_unknown_today;
00045 static struct portmap *root = NULL;
00046
00047
00048 int expmem_tcldcc(void)
00049 {
00050 int tot = 0;
00051 struct portmap *pmap;
00052
00053 for (pmap = root; pmap; pmap = pmap->next)
00054 tot += sizeof(struct portmap);
00055
00056 return tot;
00057 }
00058
00059 static int tcl_putdcc STDVAR
00060 {
00061 int j;
00062
00063 BADARGS(3, 4, " idx text ?options?");
00064
00065 if ((argc == 4) && egg_strcasecmp(argv[3], "-raw")) {
00066 Tcl_AppendResult(irp, "unknown putdcc option: should be ",
00067 "-raw", NULL);
00068 return TCL_ERROR;
00069 }
00070
00071 j = findidx(atoi(argv[1]));
00072 if (j < 0) {
00073 Tcl_AppendResult(irp, "invalid idx", NULL);
00074 return TCL_ERROR;
00075 }
00076 if (argc == 4)
00077 tputs(dcc[j].sock, argv[2], strlen(argv[2]));
00078 else
00079 dumplots(j, "", argv[2]);
00080
00081 return TCL_OK;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 static int tcl_putdccraw STDVAR
00094 {
00095 #if 0
00096 int i, j = 0, z;
00097
00098 BADARGS(4, 4, " idx size text");
00099
00100 z = atoi(argv[1]);
00101 for (i = 0; i < dcc_total; i++) {
00102 if (!z && !strcmp(dcc[i].nick, "(server)")) {
00103 j = dcc[i].sock;
00104 break;
00105 } else if (dcc[i].sock == z) {
00106 j = dcc[i].sock;
00107 break;
00108 }
00109 }
00110 if (i == dcc_total) {
00111 Tcl_AppendResult(irp, "invalid idx", NULL);
00112 return TCL_ERROR;
00113 }
00114 tputs(j, argv[3], atoi(argv[2]));
00115 return TCL_OK;
00116 #endif
00117
00118 Tcl_AppendResult(irp, "putdccraw is deprecated. "
00119 "Please use putdcc/putnow instead.", NULL);
00120 return TCL_ERROR;
00121 }
00122
00123 static int tcl_dccsimul STDVAR
00124 {
00125 int idx;
00126
00127 BADARGS(3, 3, " idx command");
00128
00129 idx = findidx(atoi(argv[1]));
00130 if (idx >= 0 && (dcc[idx].type->flags & DCT_SIMUL)) {
00131 int l = strlen(argv[2]);
00132
00133 if (l > 510) {
00134 l = 510;
00135 argv[2][510] = 0;
00136 }
00137 if (dcc[idx].type && dcc[idx].type->activity) {
00138 dcc[idx].type->activity(idx, argv[2], l);
00139 return TCL_OK;
00140 }
00141 } else {
00142 Tcl_AppendResult(irp, "invalid idx", NULL);
00143 }
00144 return TCL_ERROR;
00145 }
00146
00147
00148 static int tcl_dccbroadcast STDVAR
00149 {
00150 char msg[401];
00151
00152 BADARGS(2, 2, " message");
00153
00154 strncpyz(msg, argv[1], sizeof msg);
00155 chatout("*** %s\n", msg);
00156 botnet_send_chat(-1, botnetnick, msg);
00157 check_tcl_bcst(botnetnick, -1, msg);
00158 return TCL_OK;
00159 }
00160
00161 static int tcl_hand2idx STDVAR
00162 {
00163 int i;
00164 char s[11];
00165
00166 BADARGS(2, 2, " nickname");
00167
00168 for (i = 0; i < dcc_total; i++)
00169 if ((dcc[i].type->flags & (DCT_SIMUL | DCT_BOT)) &&
00170 !egg_strcasecmp(argv[1], dcc[i].nick)) {
00171 egg_snprintf(s, sizeof s, "%ld", dcc[i].sock);
00172 Tcl_AppendResult(irp, s, NULL);
00173 return TCL_OK;
00174 }
00175 Tcl_AppendResult(irp, "-1", NULL);
00176 return TCL_OK;
00177 }
00178
00179 static int tcl_getchan STDVAR
00180 {
00181 char s[7];
00182 int idx;
00183
00184 BADARGS(2, 2, " idx");
00185
00186 idx = findidx(atoi(argv[1]));
00187 if (idx < 0 || (dcc[idx].type != &DCC_CHAT &&
00188 dcc[idx].type != &DCC_SCRIPT)) {
00189 Tcl_AppendResult(irp, "invalid idx", NULL);
00190 return TCL_ERROR;
00191 }
00192
00193 if (dcc[idx].type == &DCC_SCRIPT)
00194 egg_snprintf(s, sizeof s, "%d", dcc[idx].u.script->u.chat->channel);
00195 else
00196 egg_snprintf(s, sizeof s, "%d", dcc[idx].u.chat->channel);
00197
00198 Tcl_AppendResult(irp, s, NULL);
00199 return TCL_OK;
00200 }
00201
00202 static int tcl_setchan STDVAR
00203 {
00204 int idx, chan;
00205 module_entry *me;
00206
00207 BADARGS(3, 3, " idx channel");
00208
00209 idx = findidx(atoi(argv[1]));
00210 if (idx < 0 || (dcc[idx].type != &DCC_CHAT &&
00211 dcc[idx].type != &DCC_SCRIPT)) {
00212 Tcl_AppendResult(irp, "invalid idx", NULL);
00213 return TCL_ERROR;
00214 }
00215 if (argv[2][0] < '0' || argv[2][0] > '9') {
00216 if (!strcmp(argv[2], "-1") || !egg_strcasecmp(argv[2], "off"))
00217 chan = -1;
00218 else {
00219 Tcl_SetVar(irp, "_chan", argv[2], 0);
00220 if (Tcl_VarEval(irp, "assoc ", "$_chan", NULL) != TCL_OK ||
00221 tcl_resultempty()) {
00222 Tcl_AppendResult(irp, "channel name is invalid", NULL);
00223 return TCL_ERROR;
00224 }
00225 chan = tcl_resultint();
00226 }
00227 } else
00228 chan = atoi(argv[2]);
00229 if ((chan < -1) || (chan > 199999)) {
00230 Tcl_AppendResult(irp, "channel out of range; must be -1 through 199999",
00231 NULL);
00232 return TCL_ERROR;
00233 }
00234 if (dcc[idx].type == &DCC_SCRIPT)
00235 dcc[idx].u.script->u.chat->channel = chan;
00236 else {
00237 int oldchan = dcc[idx].u.chat->channel;
00238
00239 if (dcc[idx].u.chat->channel >= 0) {
00240 if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS))
00241 botnet_send_part_idx(idx, "*script*");
00242 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
00243 dcc[idx].u.chat->channel);
00244 }
00245 dcc[idx].u.chat->channel = chan;
00246 if (chan < GLOBAL_CHANS)
00247 botnet_send_join_idx(idx, oldchan);
00248 check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(idx),
00249 dcc[idx].sock, dcc[idx].host);
00250 }
00251
00252 if ((me = module_find("console", 1, 1))) {
00253 Function *func = me->funcs;
00254
00255 (func[CONSOLE_DOSTORE]) (idx);
00256 }
00257 return TCL_OK;
00258 }
00259
00260 static int tcl_dccputchan STDVAR
00261 {
00262 int chan;
00263 char msg[401];
00264
00265 BADARGS(3, 3, " channel message");
00266
00267 chan = atoi(argv[1]);
00268 if ((chan < 0) || (chan > 199999)) {
00269 Tcl_AppendResult(irp, "channel out of range; must be 0 through 199999", NULL);
00270 return TCL_ERROR;
00271 }
00272 strncpyz(msg, argv[2], sizeof msg);
00273
00274 chanout_but(-1, chan, "*** %s\n", argv[2]);
00275 botnet_send_chan(-1, botnetnick, NULL, chan, argv[2]);
00276 check_tcl_bcst(botnetnick, chan, argv[2]);
00277 return TCL_OK;
00278 }
00279
00280 static int tcl_console STDVAR
00281 {
00282 int i, j, pls, arg;
00283 module_entry *me;
00284
00285 BADARGS(2, 4, " idx ?channel? ?console-modes?");
00286
00287 i = findidx(atoi(argv[1]));
00288 if (i < 0 || dcc[i].type != &DCC_CHAT) {
00289 Tcl_AppendResult(irp, "invalid idx", NULL);
00290 return TCL_ERROR;
00291 }
00292 pls = 1;
00293
00294 for (arg = 2; arg < argc; arg++) {
00295 if (argv[arg][0] && ((strchr(CHANMETA, argv[arg][0]) != NULL) ||
00296 (argv[arg][0] == '*'))) {
00297 if ((argv[arg][0] != '*') && (!findchan_by_dname(argv[arg]))) {
00298
00299
00300 if (argv[arg][0] == '+')
00301 goto do_console_flags;
00302 Tcl_AppendResult(irp, "invalid channel", NULL);
00303 return TCL_ERROR;
00304 }
00305 strncpyz(dcc[i].u.chat->con_chan, argv[arg], 81);
00306 } else {
00307 if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
00308 dcc[i].u.chat->con_flags = 0;
00309 do_console_flags:
00310 for (j = 0; j < strlen(argv[arg]); j++) {
00311 if (argv[arg][j] == '+')
00312 pls = 1;
00313 else if (argv[arg][j] == '-')
00314 pls = -1;
00315 else {
00316 char s[2];
00317
00318 s[0] = argv[arg][j];
00319 s[1] = 0;
00320 if (pls == 1)
00321 dcc[i].u.chat->con_flags |= logmodes(s);
00322 else
00323 dcc[i].u.chat->con_flags &= ~logmodes(s);
00324 }
00325 }
00326 }
00327 }
00328 Tcl_AppendElement(irp, dcc[i].u.chat->con_chan);
00329 Tcl_AppendElement(irp, masktype(dcc[i].u.chat->con_flags));
00330
00331 if (argc > 2 && (me = module_find("console", 1, 1))) {
00332 Function *func = me->funcs;
00333
00334 (func[CONSOLE_DOSTORE]) (i);
00335 }
00336 return TCL_OK;
00337 }
00338
00339 static int tcl_strip STDVAR
00340 {
00341 int i, j, pls, arg;
00342 module_entry *me;
00343
00344 BADARGS(2, 4, " idx ?strip-flags?");
00345
00346 i = findidx(atoi(argv[1]));
00347 if (i < 0 || dcc[i].type != &DCC_CHAT) {
00348 Tcl_AppendResult(irp, "invalid idx", NULL);
00349 return TCL_ERROR;
00350 }
00351 pls = 1;
00352
00353 for (arg = 2; arg < argc; arg++) {
00354 if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
00355 dcc[i].u.chat->strip_flags = 0;
00356 for (j = 0; j < strlen(argv[arg]); j++) {
00357 if (argv[arg][j] == '+')
00358 pls = 1;
00359 else if (argv[arg][j] == '-')
00360 pls = -1;
00361 else {
00362 char s[2];
00363
00364 s[0] = argv[arg][j];
00365 s[1] = 0;
00366 if (pls == 1)
00367 dcc[i].u.chat->strip_flags |= stripmodes(s);
00368 else
00369 dcc[i].u.chat->strip_flags &= ~stripmodes(s);
00370 }
00371 }
00372 }
00373 Tcl_AppendElement(irp, stripmasktype(dcc[i].u.chat->strip_flags));
00374
00375 if (argc > 2 && (me = module_find("console", 1, 1))) {
00376 Function *func = me->funcs;
00377
00378 (func[CONSOLE_DOSTORE]) (i);
00379 }
00380 return TCL_OK;
00381 }
00382
00383 static int tcl_echo STDVAR
00384 {
00385 int i;
00386 module_entry *me;
00387
00388 BADARGS(2, 3, " idx ?status?");
00389
00390 i = findidx(atoi(argv[1]));
00391 if (i < 0 || dcc[i].type != &DCC_CHAT) {
00392 Tcl_AppendResult(irp, "invalid idx", NULL);
00393 return TCL_ERROR;
00394 }
00395 if (argc == 3) {
00396 if (atoi(argv[2]))
00397 dcc[i].status |= STAT_ECHO;
00398 else
00399 dcc[i].status &= ~STAT_ECHO;
00400 }
00401 if (dcc[i].status & STAT_ECHO)
00402 Tcl_AppendResult(irp, "1", NULL);
00403 else
00404 Tcl_AppendResult(irp, "0", NULL);
00405
00406 if (argc > 2 && (me = module_find("console", 1, 1))) {
00407 Function *func = me->funcs;
00408
00409 (func[CONSOLE_DOSTORE]) (i);
00410 }
00411 return TCL_OK;
00412 }
00413
00414 static int tcl_page STDVAR
00415 {
00416 int i;
00417 char x[20];
00418 module_entry *me;
00419
00420 BADARGS(2, 3, " idx ?status?");
00421
00422 i = findidx(atoi(argv[1]));
00423 if (i < 0 || dcc[i].type != &DCC_CHAT) {
00424 Tcl_AppendResult(irp, "invalid idx", NULL);
00425 return TCL_ERROR;
00426 }
00427 if (argc == 3) {
00428 int l = atoi(argv[2]);
00429
00430 if (!l)
00431 dcc[i].status &= ~STAT_PAGE;
00432 else {
00433 dcc[i].status |= STAT_PAGE;
00434 dcc[i].u.chat->max_line = l;
00435 }
00436 }
00437 if (dcc[i].status & STAT_PAGE) {
00438 egg_snprintf(x, sizeof x, "%d", dcc[i].u.chat->max_line);
00439 Tcl_AppendResult(irp, x, NULL);
00440 } else
00441 Tcl_AppendResult(irp, "0", NULL);
00442
00443 if ((argc > 2) && (me = module_find("console", 1, 1))) {
00444 Function *func = me->funcs;
00445
00446 (func[CONSOLE_DOSTORE]) (i);
00447 }
00448 return TCL_OK;
00449 }
00450
00451 static int tcl_control STDVAR
00452 {
00453 int idx;
00454 void *hold;
00455
00456 BADARGS(3, 3, " idx command");
00457
00458 idx = findidx(atoi(argv[1]));
00459 if (idx < 0) {
00460 Tcl_AppendResult(irp, "invalid idx", NULL);
00461 return TCL_ERROR;
00462 }
00463 if (dcc[idx].type->flags & DCT_CHAT) {
00464 if (dcc[idx].u.chat->channel >= 0) {
00465 chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has gone.\n",
00466 dcc[idx].nick);
00467 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
00468 dcc[idx].u.chat->channel);
00469 botnet_send_part_idx(idx, "gone");
00470 }
00471 check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
00472 }
00473 hold = dcc[idx].u.other;
00474 dcc[idx].u.script = get_data_ptr(sizeof(struct script_info));
00475 dcc[idx].u.script->u.other = hold;
00476 dcc[idx].u.script->type = dcc[idx].type;
00477 dcc[idx].type = &DCC_SCRIPT;
00478
00479
00480 sockoptions(dcc[idx].sock, EGG_OPTION_UNSET, SOCK_BUFFER);
00481 strncpyz(dcc[idx].u.script->command, argv[2], 120);
00482 return TCL_OK;
00483 }
00484
00485 static int tcl_valididx STDVAR
00486 {
00487 int idx;
00488
00489 BADARGS(2, 2, " idx");
00490
00491 idx = findidx(atoi(argv[1]));
00492 if (idx < 0 || !(dcc[idx].type->flags & DCT_VALIDIDX))
00493 Tcl_AppendResult(irp, "0", NULL);
00494 else
00495 Tcl_AppendResult(irp, "1", NULL);
00496 return TCL_OK;
00497 }
00498
00499 static int tcl_killdcc STDVAR
00500 {
00501 int idx;
00502
00503 BADARGS(2, 3, " idx ?reason?");
00504
00505 idx = findidx(atoi(argv[1]));
00506 if (idx < 0) {
00507 Tcl_AppendResult(irp, "invalid idx", NULL);
00508 return TCL_ERROR;
00509 }
00510
00511 if ((dcc[idx].sock == STDOUT) && !backgrd)
00512 return TCL_OK;
00513
00514
00515 if (dcc[idx].type->flags & DCT_CHAT) {
00516 chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has left the %s%s%s\n",
00517 dcc[idx].nick, dcc[idx].u.chat ? "channel" : "partyline",
00518 argc == 3 ? ": " : "", argc == 3 ? argv[2] : "");
00519 botnet_send_part_idx(idx, argc == 3 ? argv[2] : "");
00520 if ((dcc[idx].u.chat->channel >= 0) &&
00521 (dcc[idx].u.chat->channel < GLOBAL_CHANS))
00522 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
00523 dcc[idx].u.chat->channel);
00524 check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
00525 }
00526 killsock(dcc[idx].sock);
00527 killtransfer(idx);
00528 lostdcc(idx);
00529 return TCL_OK;
00530 }
00531
00532 static int tcl_putbot STDVAR
00533 {
00534 int i;
00535 char msg[401];
00536
00537 BADARGS(3, 3, " botnick message");
00538
00539 i = nextbot(argv[1]);
00540 if (i < 0) {
00541 Tcl_AppendResult(irp, "bot is not on the botnet", NULL);
00542 return TCL_ERROR;
00543 }
00544 strncpyz(msg, argv[2], sizeof msg);
00545
00546 botnet_send_zapf(i, botnetnick, argv[1], msg);
00547 return TCL_OK;
00548 }
00549
00550 static int tcl_putallbots STDVAR
00551 {
00552 char msg[401];
00553
00554 BADARGS(2, 2, " message");
00555
00556 strncpyz(msg, argv[1], sizeof msg);
00557 botnet_send_zapf_broad(-1, botnetnick, NULL, msg);
00558 return TCL_OK;
00559 }
00560
00561 static int tcl_idx2hand STDVAR
00562 {
00563 int idx;
00564
00565 BADARGS(2, 2, " idx");
00566
00567 idx = findidx(atoi(argv[1]));
00568 if (idx < 0) {
00569 Tcl_AppendResult(irp, "invalid idx", NULL);
00570 return TCL_ERROR;
00571 }
00572
00573 Tcl_AppendResult(irp, dcc[idx].nick, NULL);
00574 return TCL_OK;
00575 }
00576
00577 static int tcl_islinked STDVAR
00578 {
00579 int i;
00580
00581 BADARGS(2, 2, " bot");
00582
00583 i = nextbot(argv[1]);
00584 if (i < 0)
00585 Tcl_AppendResult(irp, "0", NULL);
00586 else
00587 Tcl_AppendResult(irp, "1", NULL);
00588 return TCL_OK;
00589 }
00590
00591 static int tcl_bots STDVAR
00592 {
00593 tand_t *bot;
00594
00595 BADARGS(1, 1, "");
00596
00597 for (bot = tandbot; bot; bot = bot->next)
00598 Tcl_AppendElement(irp, bot->bot);
00599 return TCL_OK;
00600 }
00601
00602 static int tcl_botlist STDVAR
00603 {
00604 char *p, sh[2], string[20];
00605 EGG_CONST char *list[4];
00606 tand_t *bot;
00607
00608 BADARGS(1, 1, "");
00609
00610 sh[1] = 0;
00611 list[3] = sh;
00612 list[2] = string;
00613 for (bot = tandbot; bot; bot = bot->next) {
00614 list[0] = bot->bot;
00615 list[1] = (bot->uplink == (tand_t *) 1) ? botnetnick : bot->uplink->bot;
00616 strncpyz(string, int_to_base10(bot->ver), sizeof string);
00617 sh[0] = bot->share;
00618 p = Tcl_Merge(4, list);
00619 Tcl_AppendElement(irp, p);
00620 Tcl_Free((char *) p);
00621 }
00622 return TCL_OK;
00623 }
00624
00625 static int tcl_dcclist STDVAR
00626 {
00627 int i;
00628 char *p, idxstr[10], timestamp[11], other[160];
00629 long tv;
00630 EGG_CONST char *list[6];
00631
00632 BADARGS(1, 2, " ?type?");
00633
00634 for (i = 0; i < dcc_total; i++) {
00635 if (argc == 1 || ((argc == 2) && (dcc[i].type &&
00636 !egg_strcasecmp(dcc[i].type->name, argv[1])))) {
00637 egg_snprintf(idxstr, sizeof idxstr, "%ld", dcc[i].sock);
00638 tv = dcc[i].timeval;
00639 egg_snprintf(timestamp, sizeof timestamp, "%ld", tv);
00640 if (dcc[i].type && dcc[i].type->display)
00641 dcc[i].type->display(i, other);
00642 else {
00643 egg_snprintf(other, sizeof other, "?:%lX !! ERROR !!",
00644 (long) dcc[i].type);
00645 break;
00646 }
00647 list[0] = idxstr;
00648 list[1] = dcc[i].nick;
00649 list[2] = dcc[i].host;
00650 list[3] = dcc[i].type ? dcc[i].type->name : "*UNKNOWN*";
00651 list[4] = other;
00652 list[5] = timestamp;
00653 p = Tcl_Merge(6, list);
00654 Tcl_AppendElement(irp, p);
00655 Tcl_Free((char *) p);
00656 }
00657 }
00658 return TCL_OK;
00659 }
00660
00661 static int tcl_whom STDVAR
00662 {
00663 int chan, i;
00664 char c[2], idle[11], work[20], *p;
00665 long tv = 0;
00666 EGG_CONST char *list[7];
00667
00668 BADARGS(2, 2, " chan");
00669
00670 if (argv[1][0] == '*')
00671 chan = -1;
00672 else {
00673 if ((argv[1][0] < '0') || (argv[1][0] > '9')) {
00674 Tcl_SetVar(interp, "_chan", argv[1], 0);
00675 if ((Tcl_VarEval(interp, "assoc ", "$_chan", NULL) != TCL_OK) ||
00676 tcl_resultempty()) {
00677 Tcl_AppendResult(irp, "channel name is invalid", NULL);
00678 return TCL_ERROR;
00679 }
00680 chan = tcl_resultint();
00681 } else
00682 chan = atoi(argv[1]);
00683 if ((chan < 0) || (chan > 199999)) {
00684 Tcl_AppendResult(irp, "channel out of range; must be 0 through 199999",
00685 NULL);
00686 return TCL_ERROR;
00687 }
00688 }
00689 for (i = 0; i < dcc_total; i++)
00690 if (dcc[i].type == &DCC_CHAT) {
00691 if (dcc[i].u.chat->channel == chan || chan == -1) {
00692 c[0] = geticon(i);
00693 c[1] = 0;
00694 tv = (now - dcc[i].timeval) / 60;
00695 egg_snprintf(idle, sizeof idle, "%li", tv);
00696 list[0] = dcc[i].nick;
00697 list[1] = botnetnick;
00698 list[2] = dcc[i].host;
00699 list[3] = c;
00700 list[4] = idle;
00701 list[5] = dcc[i].u.chat->away ? dcc[i].u.chat->away : "";
00702 if (chan == -1) {
00703 egg_snprintf(work, sizeof work, "%d", dcc[i].u.chat->channel);
00704 list[6] = work;
00705 }
00706 p = Tcl_Merge((chan == -1) ? 7 : 6, list);
00707 Tcl_AppendElement(irp, p);
00708 Tcl_Free((char *) p);
00709 }
00710 }
00711 for (i = 0; i < parties; i++) {
00712 if (party[i].chan == chan || chan == -1) {
00713 c[0] = party[i].flag;
00714 c[1] = 0;
00715 if (party[i].timer == 0L)
00716 strcpy(idle, "0");
00717 else {
00718 tv = (now - party[i].timer) / 60;
00719 egg_snprintf(idle, sizeof idle, "%li", tv);
00720 }
00721 list[0] = party[i].nick;
00722 list[1] = party[i].bot;
00723 list[2] = party[i].from ? party[i].from : "";
00724 list[3] = c;
00725 list[4] = idle;
00726 list[5] = party[i].status & PLSTAT_AWAY ? party[i].away : "";
00727 if (chan == -1) {
00728 egg_snprintf(work, sizeof work, "%d", party[i].chan);
00729 list[6] = work;
00730 }
00731 p = Tcl_Merge((chan == -1) ? 7 : 6, list);
00732 Tcl_AppendElement(irp, p);
00733 Tcl_Free((char *) p);
00734 }
00735 }
00736 return TCL_OK;
00737 }
00738
00739 static int tcl_dccused STDVAR
00740 {
00741 char s[20];
00742
00743 BADARGS(1, 1, "");
00744
00745 egg_snprintf(s, sizeof s, "%d", dcc_total);
00746 Tcl_AppendResult(irp, s, NULL);
00747 return TCL_OK;
00748 }
00749
00750 static int tcl_getdccidle STDVAR
00751 {
00752 int x, idx;
00753 char s[21];
00754
00755 BADARGS(2, 2, " idx");
00756
00757 idx = findidx(atoi(argv[1]));
00758 if (idx < 0) {
00759 Tcl_AppendResult(irp, "invalid idx", NULL);
00760 return TCL_ERROR;
00761 }
00762 x = (now - dcc[idx].timeval);
00763
00764 egg_snprintf(s, sizeof s, "%d", x);
00765 Tcl_AppendElement(irp, s);
00766 return TCL_OK;
00767 }
00768
00769 static int tcl_getdccaway STDVAR
00770 {
00771 int idx;
00772
00773 BADARGS(2, 2, " idx");
00774
00775 idx = findidx(atol(argv[1]));
00776 if (idx < 0 || dcc[idx].type != &DCC_CHAT) {
00777 Tcl_AppendResult(irp, "invalid idx", NULL);
00778 return TCL_ERROR;
00779 }
00780 if (dcc[idx].u.chat->away == NULL)
00781 return TCL_OK;
00782
00783 Tcl_AppendResult(irp, dcc[idx].u.chat->away, NULL);
00784 return TCL_OK;
00785 }
00786
00787 static int tcl_setdccaway STDVAR
00788 {
00789 int idx;
00790
00791 BADARGS(3, 3, " idx message");
00792
00793 idx = findidx(atol(argv[1]));
00794 if (idx < 0 || dcc[idx].type != &DCC_CHAT) {
00795 Tcl_AppendResult(irp, "invalid idx", NULL);
00796 return TCL_ERROR;
00797 }
00798 if (!argv[2][0]) {
00799 if (dcc[idx].u.chat->away != NULL)
00800 not_away(idx);
00801 return TCL_OK;
00802 }
00803 set_away(idx, argv[2]);
00804 return TCL_OK;
00805 }
00806
00807 static int tcl_link STDVAR
00808 {
00809 int x, i;
00810 char bot[HANDLEN + 1], bot2[HANDLEN + 1];
00811
00812 BADARGS(2, 3, " ?via-bot? bot");
00813
00814 strncpyz(bot, argv[1], sizeof bot);
00815 if (argc == 3) {
00816 x = 1;
00817 strncpyz(bot2, argv[2], sizeof bot2);
00818 i = nextbot(bot);
00819 if (i < 0)
00820 x = 0;
00821 else
00822 botnet_send_link(i, botnetnick, bot, bot2);
00823 } else
00824 x = botlink("", -2, bot);
00825
00826 egg_snprintf(bot, sizeof bot, "%d", x);
00827 Tcl_AppendResult(irp, bot, NULL);
00828 return TCL_OK;
00829 }
00830
00831 static int tcl_unlink STDVAR
00832 {
00833 int i, x;
00834 char bot[HANDLEN + 1];
00835
00836 BADARGS(2, 3, " bot ?comment?");
00837
00838 strncpyz(bot, argv[1], sizeof bot);
00839 i = nextbot(bot);
00840 if (i < 0)
00841 x = 0;
00842 else {
00843 x = 1;
00844 if (!egg_strcasecmp(bot, dcc[i].nick))
00845 x = botunlink(-2, bot, argv[2], botnetnick);
00846 else
00847 botnet_send_unlink(i, botnetnick, lastbot(bot), bot, argv[2]);
00848 }
00849 egg_snprintf(bot, sizeof bot, "%d", x);
00850
00851 Tcl_AppendResult(irp, bot, NULL);
00852 return TCL_OK;
00853 }
00854
00855 static int tcl_connect STDVAR
00856 {
00857 int i, z, sock;
00858 char s[81];
00859
00860 BADARGS(3, 3, " hostname port");
00861
00862 if (dcc_total == max_dcc && increase_socks_max()) {
00863 Tcl_AppendResult(irp, "out of dcc table space", NULL);
00864 return TCL_ERROR;
00865 }
00866 sock = getsock(0);
00867
00868 if (sock < 0) {
00869 Tcl_AppendResult(irp, MISC_NOFREESOCK, NULL);
00870 return TCL_ERROR;
00871 }
00872 z = open_telnet_raw(sock, argv[1], atoi(argv[2]));
00873 if (z < 0) {
00874 killsock(sock);
00875 if (z == -2)
00876 strncpyz(s, "DNS lookup failed", sizeof s);
00877 else
00878 neterror(s);
00879 Tcl_AppendResult(irp, s, NULL);
00880 return TCL_ERROR;
00881 }
00882 i = new_dcc(&DCC_SOCKET, 0);
00883 dcc[i].sock = sock;
00884 dcc[i].port = atoi(argv[2]);
00885 strcpy(dcc[i].nick, "*");
00886 strncpyz(dcc[i].host, argv[1], UHOSTMAX);
00887 egg_snprintf(s, sizeof s, "%d", sock);
00888 Tcl_AppendResult(irp, s, NULL);
00889 return TCL_OK;
00890 }
00891
00892
00893
00894
00895
00896
00897
00898 static int tcl_listen STDVAR
00899 {
00900 int i, j, idx = -1, port, realport;
00901 char s[11], msg[256];
00902 struct portmap *pmap = NULL, *pold = NULL;
00903
00904 BADARGS(3, 5, " port type ?mask?/?proc ?flag??");
00905
00906 port = realport = atoi(argv[1]);
00907 for (pmap = root; pmap; pold = pmap, pmap = pmap->next)
00908 if (pmap->realport == port) {
00909 port = pmap->mappedto;
00910 break;
00911 }
00912 for (i = 0; i < dcc_total; i++)
00913 if ((dcc[i].type == &DCC_TELNET) && (dcc[i].port == port))
00914 idx = i;
00915 if (!egg_strcasecmp(argv[2], "off")) {
00916 if (pmap) {
00917 if (pold)
00918 pold->next = pmap->next;
00919 else
00920 root = pmap->next;
00921 nfree(pmap);
00922 }
00923
00924 if (idx < 0) {
00925 Tcl_AppendResult(irp, "no such listen port is open", NULL);
00926 return TCL_ERROR;
00927 }
00928 killsock(dcc[idx].sock);
00929 lostdcc(idx);
00930 return TCL_OK;
00931 }
00932 if (idx < 0) {
00933
00934 if (dcc_total >= max_dcc && increase_socks_max()) {
00935 Tcl_AppendResult(irp, "No more DCC slots available.", NULL);
00936 return TCL_ERROR;
00937 }
00938
00939 j = port + 20;
00940 i = -1;
00941 while (port < j && i < 0) {
00942 i = open_listen(&port);
00943 if (i == -1)
00944 port++;
00945 else if (i == -2)
00946 break;
00947 }
00948 if (i == -1) {
00949 egg_snprintf(msg, sizeof msg, "Couldn't listen on port '%d' on the "
00950 "given address. Please make sure 'my-ip' is set correctly, "
00951 "or try a different port.", realport);
00952 Tcl_AppendResult(irp, msg, NULL);
00953 return TCL_ERROR;
00954 } else if (i == -2) {
00955 Tcl_AppendResult(irp, "Couldn't assign the requested IP. Please make "
00956 "sure 'my-ip' is set properly.", NULL);
00957 return TCL_ERROR;
00958 }
00959 idx = new_dcc(&DCC_TELNET, 0);
00960 dcc[idx].addr = iptolong(getmyip());
00961 dcc[idx].port = port;
00962 dcc[idx].sock = i;
00963 dcc[idx].timeval = now;
00964 }
00965
00966 if (!strcmp(argv[2], "script")) {
00967 strcpy(dcc[idx].nick, "(script)");
00968 if (argc < 4) {
00969 Tcl_AppendResult(irp, "a proc name must be specified for a script listen", NULL);
00970 killsock(dcc[idx].sock);
00971 lostdcc(idx);
00972 return TCL_ERROR;
00973 }
00974 if (argc == 5) {
00975 if (strcmp(argv[4], "pub")) {
00976 Tcl_AppendResult(irp, "unknown flag: ", argv[4], ". allowed flags: pub",
00977 NULL);
00978 killsock(dcc[idx].sock);
00979 lostdcc(idx);
00980 return TCL_ERROR;
00981 }
00982 dcc[idx].status = LSTN_PUBLIC;
00983 }
00984 strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
00985 egg_snprintf(s, sizeof s, "%d", port);
00986 Tcl_AppendResult(irp, s, NULL);
00987 return TCL_OK;
00988 }
00989
00990 if (!strcmp(argv[2], "bots"))
00991 strcpy(dcc[idx].nick, "(bots)");
00992 else if (!strcmp(argv[2], "users"))
00993 strcpy(dcc[idx].nick, "(users)");
00994 else if (!strcmp(argv[2], "all"))
00995 strcpy(dcc[idx].nick, "(telnet)");
00996 if (!dcc[idx].nick[0]) {
00997 Tcl_AppendResult(irp, "invalid listen type: must be one of ",
00998 "bots, users, all, off, script", NULL);
00999 killsock(dcc[idx].sock);
01000 dcc_total--;
01001 return TCL_ERROR;
01002 }
01003 if (argc == 4)
01004 strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
01005 else
01006 strcpy(dcc[idx].host, "*");
01007 egg_snprintf(s, sizeof s, "%d", port);
01008 Tcl_AppendResult(irp, s, NULL);
01009 if (!pmap) {
01010 pmap = nmalloc(sizeof(struct portmap));
01011 pmap->next = root;
01012 root = pmap;
01013 }
01014 pmap->realport = realport;
01015 pmap->mappedto = port;
01016 putlog(LOG_MISC, "*", "Listening at telnet port %d (%s).", port, argv[2]);
01017 return TCL_OK;
01018 }
01019
01020 static int tcl_boot STDVAR
01021 {
01022 char who[NOTENAMELEN + 1];
01023 int i, ok = 0;
01024
01025 BADARGS(2, 3, " user@bot ?reason?");
01026
01027 strncpyz(who, argv[1], sizeof who);
01028
01029 if (strchr(who, '@') != NULL) {
01030 char whonick[HANDLEN + 1];
01031
01032 splitc(whonick, who, '@');
01033 whonick[HANDLEN] = 0;
01034 if (!egg_strcasecmp(who, botnetnick))
01035 strncpyz(who, whonick, sizeof who);
01036 else if (remote_boots > 0) {
01037 i = nextbot(who);
01038 if (i < 0)
01039 return TCL_OK;
01040 botnet_send_reject(i, botnetnick, NULL, whonick, who,
01041 argv[2] ? argv[2] : "");
01042 } else
01043 return TCL_OK;
01044 }
01045 for (i = 0; i < dcc_total; i++)
01046 if (!ok && (dcc[i].type->flags & DCT_CANBOOT) &&
01047 !egg_strcasecmp(dcc[i].nick, who)) {
01048 do_boot(i, botnetnick, argv[2] ? argv[2] : "");
01049 ok = 1;
01050 }
01051 return TCL_OK;
01052 }
01053
01054 static int tcl_rehash STDVAR
01055 {
01056 BADARGS(1, 1, "");
01057
01058 if (make_userfile) {
01059 putlog(LOG_MISC, "*", USERF_NONEEDNEW);
01060 make_userfile = 0;
01061 }
01062 write_userfile(-1);
01063
01064 putlog(LOG_MISC, "*", USERF_REHASHING);
01065 do_restart = -2;
01066 return TCL_OK;
01067 }
01068
01069 static int tcl_restart STDVAR
01070 {
01071 BADARGS(1, 1, "");
01072
01073 if (!backgrd) {
01074 Tcl_AppendResult(interp, "You can't restart a -n bot", NULL);
01075 return TCL_ERROR;
01076 }
01077 if (make_userfile) {
01078 putlog(LOG_MISC, "*", USERF_NONEEDNEW);
01079 make_userfile = 0;
01080 }
01081 write_userfile(-1);
01082 putlog(LOG_MISC, "*", MISC_RESTARTING);
01083 wipe_timers(interp, &utimer);
01084 wipe_timers(interp, &timer);
01085 do_restart = -1;
01086 return TCL_OK;
01087 }
01088
01089 static int tcl_traffic STDVAR
01090 {
01091 char buf[1024];
01092 unsigned long out_total_today, out_total;
01093 unsigned long in_total_today, in_total;
01094
01095
01096 sprintf(buf, "irc %ld %ld %ld %ld", itraffic_irc_today, itraffic_irc +
01097 itraffic_irc_today, otraffic_irc_today,
01098 otraffic_irc + otraffic_irc_today);
01099 Tcl_AppendElement(irp, buf);
01100
01101
01102 sprintf(buf, "botnet %ld %ld %ld %ld", itraffic_bn_today, itraffic_bn +
01103 itraffic_bn_today, otraffic_bn_today,
01104 otraffic_bn + otraffic_bn_today);
01105 Tcl_AppendElement(irp, buf);
01106
01107
01108 sprintf(buf, "partyline %ld %ld %ld %ld", itraffic_dcc_today, itraffic_dcc +
01109 itraffic_dcc_today, otraffic_dcc_today,
01110 otraffic_dcc + otraffic_dcc_today);
01111 Tcl_AppendElement(irp, buf);
01112
01113
01114 sprintf(buf, "transfer %ld %ld %ld %ld", itraffic_trans_today,
01115 itraffic_trans + itraffic_trans_today, otraffic_trans_today,
01116 otraffic_trans + otraffic_trans_today);
01117 Tcl_AppendElement(irp, buf);
01118
01119
01120 sprintf(buf, "misc %ld %ld %ld %ld", itraffic_unknown_today,
01121 itraffic_unknown + itraffic_unknown_today, otraffic_unknown_today,
01122 otraffic_unknown + otraffic_unknown_today);
01123 Tcl_AppendElement(irp, buf);
01124
01125
01126 in_total_today = itraffic_irc_today + itraffic_bn_today +
01127 itraffic_dcc_today + itraffic_trans_today +
01128 itraffic_unknown_today;
01129 in_total = in_total_today + itraffic_irc + itraffic_bn + itraffic_dcc +
01130 itraffic_trans + itraffic_unknown;
01131 out_total_today = otraffic_irc_today + otraffic_bn_today +
01132 otraffic_dcc_today + itraffic_trans_today +
01133 otraffic_unknown_today;
01134 out_total = out_total_today + otraffic_irc + otraffic_bn + otraffic_dcc +
01135 otraffic_trans + otraffic_unknown;
01136 sprintf(buf, "total %ld %ld %ld %ld", in_total_today, in_total,
01137 out_total_today, out_total);
01138 Tcl_AppendElement(irp, buf);
01139 return TCL_OK;
01140 }
01141
01142 tcl_cmds tcldcc_cmds[] = {
01143 {"putdcc", tcl_putdcc},
01144 {"putdccraw", tcl_putdccraw},
01145 {"putidx", tcl_putdcc},
01146 {"dccsimul", tcl_dccsimul},
01147 {"dccbroadcast", tcl_dccbroadcast},
01148 {"hand2idx", tcl_hand2idx},
01149 {"getchan", tcl_getchan},
01150 {"setchan", tcl_setchan},
01151 {"dccputchan", tcl_dccputchan},
01152 {"console", tcl_console},
01153 {"strip", tcl_strip},
01154 {"echo", tcl_echo},
01155 {"page", tcl_page},
01156 {"control", tcl_control},
01157 {"valididx", tcl_valididx},
01158 {"killdcc", tcl_killdcc},
01159 {"putbot", tcl_putbot},
01160 {"putallbots", tcl_putallbots},
01161 {"idx2hand", tcl_idx2hand},
01162 {"bots", tcl_bots},
01163 {"botlist", tcl_botlist},
01164 {"dcclist", tcl_dcclist},
01165 {"whom", tcl_whom},
01166 {"dccused", tcl_dccused},
01167 {"getdccidle", tcl_getdccidle},
01168 {"getdccaway", tcl_getdccaway},
01169 {"setdccaway", tcl_setdccaway},
01170 {"islinked", tcl_islinked},
01171 {"link", tcl_link},
01172 {"unlink", tcl_unlink},
01173 {"connect", tcl_connect},
01174 {"listen", tcl_listen},
01175 {"boot", tcl_boot},
01176 {"rehash", tcl_rehash},
01177 {"restart", tcl_restart},
01178 {"traffic", tcl_traffic},
01179 {NULL, NULL}
01180 };