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

Annotation of /eggdrop1.9/src/tcldcc.c

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


Revision 1.7 - (hide annotations) (download) (as text)
Wed Nov 10 21:35:03 1999 UTC (19 years, 6 months ago) by fabian
Branch: MAIN
Changes since 1.6: +8 -8 lines
File MIME type: text/x-chdr
Resync with 1.4

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23