/[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.18 - (hide annotations) (download) (as text)
Thu Aug 31 18:08:56 2000 UTC (18 years, 8 months ago) by fabian
Branch: MAIN
Changes since 1.17: +6 -5 lines
File MIME type: text/x-chdr
fabian: dccsimul_errmsg patch

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23