/[cvs]/eggdrop1.4/src/tcldcc.c
ViewVC logotype

Contents of /eggdrop1.4/src/tcldcc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Wed Jun 23 19:51:32 1999 UTC (22 years, 4 months ago) by segfault
Branch: eggdev
CVS Tags: start
Changes since 1.1: +0 -0 lines
File MIME type: text/x-chdr
Eggdrop 1.3.28 CVS Code

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23