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

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

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


Revision 1.53 - (show annotations) (download) (as text)
Wed Mar 13 00:27:33 2002 UTC (17 years, 8 months ago) by stdarg
Branch: MAIN
Changes since 1.52: +3 -3 lines
File MIME type: text/x-chdr
* All the tcl commands in tclmisc.c except for loadmodule (has to wait for tcl-free config)
* Fixed some dcc stuff that got commented out instead of changed.. oops

1 /*
2 * tcldcc.c -- handles:
3 * Tcl stubs for the dcc commands
4 *
5 * $Id: tcldcc.c,v 1.52 2002/03/11 20:16:30 stdarg Exp $
6 */
7 /*
8 * Copyright (C) 1997 Robey Pointer
9 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
10 *
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 */
25
26 #include "main.h"
27 #include "tandem.h"
28 #include "modules.h"
29 #include "script_api.h"
30 #include "script.h"
31 #include "logfile.h"
32 #include "misc.h"
33
34 extern struct dcc_t *dcc;
35 extern int dcc_total, backgrd, parties, make_userfile,
36 do_restart, remote_boots, max_dcc;
37 extern char botnetnick[];
38 extern party_t *party;
39 extern tand_t *tandbot;
40 extern time_t now;
41
42 /* Traffic stuff. */
43 extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc, itraffic_irc_today, otraffic_bn, otraffic_bn_today, itraffic_bn, itraffic_bn_today, otraffic_dcc, otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today, otraffic_trans, otraffic_trans_today, itraffic_trans, itraffic_trans_today, otraffic_unknown, otraffic_unknown_today, itraffic_unknown, itraffic_unknown_today;
44
45 static struct portmap *root = NULL;
46
47
48 /***********************************************************************/
49
50 static int script_putdcc(int idx, char *text)
51 {
52 if (idx < 0 || idx >= dcc_total || !dcc[idx].type) return(1);
53 dumplots(-(dcc[idx].sock), "", text);
54 return(0);
55 }
56
57 /* Allows tcl scripts to send out raw data. Can be used for fast server
58 * write (idx=-1)
59 *
60 * usage:
61 * putdccraw <idx> <size> <rawdata>
62 * example:
63 * putdccraw 6 13 "eggdrop rulz\n"
64 *
65 * (added by drummer@sophia.jpte.hu)
66 */
67
68 static int script_putdccraw(int idx, int len, char *text)
69 {
70 int i;
71
72 if (idx == -1) {
73 /* -1 means search for the server's idx. */
74 for (i = 0; i < dcc_total; i++) {
75 if (!strcmp(dcc[i].nick, "(server)")) {
76 idx = i;
77 break;
78 }
79 }
80 }
81 if (idx < 0 || idx >= dcc_total || !dcc[idx].type) return(1);
82 tputs(dcc[idx].sock, text, len);
83 return(0);
84 }
85
86 static int script_dccsimul(int idx, char *cmd)
87 {
88 int len;
89 if (idx < 0 || !dcc->type || !(dcc[idx].type->flags & DCT_SIMUL)
90 || !(dcc[idx].type->activity)) return(1);
91
92 len = strlen(cmd);
93 if (len > 510) len = 510;
94
95 dcc[idx].type->activity(idx, cmd, len);
96 return(0);
97 }
98
99 static int script_dccbroadcast(char *msg)
100 {
101 chatout("*** %s\n", msg);
102 botnet_send_chat(-1, botnetnick, msg);
103 return(0);
104 }
105
106 static int script_hand2idx(char *nick)
107 {
108 int i;
109
110 for (i = 0; i < dcc_total; i++) {
111 if ((dcc[i].type) && (dcc[i].type->flags & DCT_SIMUL) &&
112 !strcasecmp(nick, dcc[i].nick)) {
113 return(i);
114 }
115 }
116 return(-1);
117 }
118
119 static int script_getchan(int idx)
120 {
121 if (idx < 0 || !(dcc[idx].type) ||
122 (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
123 return(-2);
124 }
125 if (dcc[idx].type == &DCC_SCRIPT)
126 return(dcc[idx].u.script->u.chat->channel);
127 else
128 return(dcc[idx].u.chat->channel);
129 }
130
131 static int script_setchan(int idx, int chan)
132 {
133 int oldchan;
134
135 if (idx < 0 || !(dcc[idx].type) ||
136 (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
137 return(1);
138 }
139
140 if ((chan < -1) || (chan > 199999)) {
141 return(1);
142 }
143 if (dcc[idx].type == &DCC_SCRIPT) {
144 dcc[idx].u.script->u.chat->channel = chan;
145 return(0);
146 }
147
148 oldchan = dcc[idx].u.chat->channel;
149
150 if (oldchan >= 0) {
151 if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS)) botnet_send_part_idx(idx, "*script*");
152 check_tcl_chpt(botnetnick, dcc[idx].nick, idx, oldchan);
153 }
154 dcc[idx].u.chat->channel = chan;
155 if (chan < GLOBAL_CHANS) botnet_send_join_idx(idx, oldchan);
156 check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(dcc[idx].user),
157 idx, dcc[idx].host);
158 return(0);
159 }
160
161 static int script_dccputchan(int chan, char *msg)
162 {
163 if ((chan < 0) || (chan > 199999)) return(1);
164 chanout_but(-1, chan, "*** %s\n", msg);
165 botnet_send_chan(-1, botnetnick, NULL, chan, msg);
166 check_tcl_bcst(botnetnick, chan, msg);
167 return(0);
168 }
169
170 static int script_console(script_var_t *retval, int nargs, int idx, char *what)
171 {
172 static char *view[2];
173 char str[2];
174 int plus;
175
176 str[1] = 0;
177
178 if (idx < 0 || idx >= dcc_total || !dcc[idx].type || dcc[idx].type != &DCC_CHAT) {
179 retval->value = "invalid idx";
180 retval->len = 10;
181 retval->type = SCRIPT_ERROR | SCRIPT_STRING;
182 }
183
184 retval->type = SCRIPT_ARRAY | SCRIPT_STRING;
185 retval->len = 2;
186 view[0] = dcc[idx].u.chat->con_chan;
187 view[1] = masktype(dcc[idx].u.chat->con_flags);
188 retval->value = (void *)view;
189
190 if (nargs != 2) {
191 view[1] = masktype(dcc[idx].u.chat->con_flags);
192 return(0); /* Done. */
193 }
194
195 /* They want to change something. */
196 if (strchr(CHANMETA, what[0]) != NULL) {
197 /* The channel. */
198 strncpyz(dcc[idx].u.chat->con_chan, what, 80);
199 return(0);
200 }
201
202 /* The flags. */
203 if (*what != '+' && *what != '-') dcc[idx].u.chat->con_flags = 0;
204 for (plus = 1; *what; what++) {
205 if (*what == '-') plus = 0;
206 else if (*what == '+') plus = 1;
207 else {
208 str[0] = *what;
209 if (plus) dcc[idx].u.chat->con_flags |= logmodes(str);
210 else dcc[idx].u.chat->con_flags &= (~logmodes(str));
211 }
212 }
213 view[1] = masktype(dcc[idx].u.chat->con_flags);
214 return(0);
215 }
216
217 static int script_strip(script_var_t *retval, int nargs, int idx, char *what)
218 {
219 char str[2];
220 int plus;
221
222 str[1] = 0;
223
224 if (idx < 0 || idx >= dcc_total || !dcc[idx].type || dcc[idx].type != &DCC_CHAT) {
225 retval->value = "invalid idx";
226 retval->len = 10;
227 retval->type = SCRIPT_ERROR | SCRIPT_STRING;
228 }
229
230 retval->len = -1;
231 retval->type = SCRIPT_STRING;
232
233 if (nargs == 1) {
234 retval->value = stripmasktype(dcc[idx].u.chat->strip_flags);
235 return(0);
236 }
237
238 /* The flags. */
239 if (*what != '+' && *what != '-') dcc[idx].u.chat->strip_flags = 0;
240 for (plus = 1; *what; what++) {
241 if (*what == '-') plus = 0;
242 else if (*what == '+') plus = 1;
243 else {
244 str[0] = *what;
245 if (plus) dcc[idx].u.chat->con_flags |= stripmodes(str);
246 else dcc[idx].u.chat->con_flags &= (~stripmodes(str));
247 }
248 }
249
250 retval->value = stripmasktype(dcc[idx].u.chat->strip_flags);
251 return(0);
252 }
253
254 static int script_echo(int nargs, int idx, int status)
255 {
256 if (idx < 0 || idx >= dcc_total || !dcc[idx].type || dcc[idx].type != &DCC_CHAT) return(0);
257 if (nargs == 2) {
258 if (status) dcc[idx].status |= STAT_ECHO;
259 else dcc[idx].status &= (~STAT_ECHO);
260 }
261
262 if (dcc[idx].status & STAT_ECHO) return(1);
263 return(0);
264 }
265
266 static int script_page(int nargs, int idx, int status)
267 {
268 if (idx < 0 || idx >= dcc_total || !dcc[idx].type || dcc[idx].type != &DCC_CHAT) return(0);
269
270 if (nargs == 2) {
271 if (status) {
272 dcc[idx].status |= STAT_PAGE;
273 dcc[idx].u.chat->max_line = status;
274 }
275 else dcc[idx].status &= (~STAT_PAGE);
276 }
277 if (dcc[idx].status & STAT_PAGE) return(dcc[idx].u.chat->max_line);
278 return(0);
279 }
280
281 static int tcl_control STDVAR
282 {
283 int idx;
284 void *hold;
285
286 BADARGS(3, 3, " idx command");
287 idx = atoi(argv[1]);
288 if (idx < 0) {
289 Tcl_AppendResult(irp, "invalid idx", NULL);
290 return TCL_ERROR;
291 }
292 if (dcc[idx].type && dcc[idx].type->flags & DCT_CHAT) {
293 if (dcc[idx].u.chat->channel >= 0) {
294 chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has gone.\n",
295 dcc[idx].nick);
296 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
297 dcc[idx].u.chat->channel);
298 botnet_send_part_idx(idx, "gone");
299 }
300 check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
301 }
302 hold = dcc[idx].u.other;
303 dcc[idx].u.script = calloc(1, sizeof(struct script_info));
304 dcc[idx].u.script->u.other = hold;
305 dcc[idx].u.script->type = dcc[idx].type;
306 dcc[idx].type = &DCC_SCRIPT;
307 /* Do not buffer data anymore. All received and stored data is passed
308 over to the dcc functions from now on. */
309 sockoptions(dcc[idx].sock, EGG_OPTION_UNSET, SOCK_BUFFER);
310 strncpyz(dcc[idx].u.script->command, argv[2], 120);
311 return TCL_OK;
312 }
313
314 static int script_valididx(int idx)
315 {
316 if (idx < 0 || idx >= dcc_total || !dcc[idx].type || !(dcc[idx].type->flags & DCT_VALIDIDX)) return(0);
317 return(1);
318 }
319
320 static int tcl_killdcc STDVAR
321 {
322 int idx;
323
324 BADARGS(2, 3, " idx ?reason?");
325 idx = atoi(argv[1]);
326 if (idx < 0) {
327 Tcl_AppendResult(irp, "invalid idx", NULL);
328 return TCL_ERROR;
329 }
330 /* Don't kill terminal socket */
331 if ((dcc[idx].sock == STDOUT) && !backgrd)
332 return TCL_OK;
333 /* Make sure 'whom' info is updated for other bots */
334 if (dcc[idx].type->flags & DCT_CHAT) {
335 chanout_but(idx, dcc[idx].u.chat->channel, "*** %s has left the %s%s%s\n",
336 dcc[idx].nick, dcc[idx].u.chat ? "channel" : "partyline",
337 argc == 3 ? ": " : "", argc == 3 ? argv[2] : "");
338 botnet_send_part_idx(idx, argc == 3 ? argv[2] : "");
339 if ((dcc[idx].u.chat->channel >= 0) && (dcc[idx].u.chat->channel < GLOBAL_CHANS)) {
340 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, dcc[idx].u.chat->channel);
341 }
342 check_tcl_chof(dcc[idx].nick, dcc[idx].sock);
343 /* Notice is sent to the party line, the script can add a reason. */
344 }
345 killsock(dcc[idx].sock);
346 lostdcc(idx);
347 return TCL_OK;
348 }
349
350 static int script_putbot(char *target, char *text)
351 {
352 int i;
353
354 i = nextbot(target);
355 if (i < 0) return(1);
356 botnet_send_zapf(i, botnetnick, target, text);
357 return(0);
358 }
359
360 static int script_putallbots(char *text)
361 {
362 botnet_send_zapf_broad(-1, botnetnick, NULL, text);
363 return(0);
364 }
365
366 static char *script_idx2hand(int idx)
367 {
368 if (idx < 0 || idx >= dcc_total || !(dcc[idx].type) || !(dcc[idx].nick)) return("");
369 return(dcc[idx].nick);
370 }
371
372 static int script_islinked(char *bot)
373 {
374 return nextbot(bot);
375 }
376
377 static int script_bots(script_var_t *retval)
378 {
379 char **botlist = NULL;
380 int nbots = 0;
381 tand_t *bot;
382
383 for (bot = tandbot; bot; bot = bot->next) {
384 nbots++;
385 botlist = (char **)realloc(botlist, sizeof(char *) * nbots);
386 botlist[nbots-1] = strdup(bot->bot);
387 }
388 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_STRING;
389 retval->value = (void *)botlist;
390 retval->len = nbots;
391 return(0);
392 }
393
394 static int script_botlist(script_var_t *retval)
395 {
396 tand_t *bot;
397 script_var_t *sublist, *nick, *uplink, *version, *share;
398 char sharestr[2];
399
400 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR;
401 retval->len = 0;
402 retval->value = NULL;
403 sharestr[1] = 0;
404 for (bot = tandbot; bot; bot = bot->next) {
405 nick = script_string(bot->bot, -1);
406 uplink = script_string((bot->uplink == (tand_t *)1) ? botnetnick : bot->uplink->bot, -1);
407 version = script_int(bot->ver);
408 sharestr[0] = bot->share;
409 share = script_string(strdup(sharestr), -1);
410
411 sublist = script_list(4, nick, uplink, version, share);
412 script_list_append(retval, sublist);
413 }
414 return(0);
415 }
416
417 /* list of { idx nick host type {other} timestamp}
418 */
419 static int script_dcclist(script_var_t *retval, char *match)
420 {
421 int i;
422 script_var_t *sublist, *idx, *nick, *host, *type, *othervar, *timestamp;
423 char other[160];
424
425 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR;
426 retval->len = 0;
427 retval->value = NULL;
428 for (i = 0; i < dcc_total; i++) {
429 if (!(dcc[i].type)) continue;
430 if (match && strcasecmp(dcc[i].type->name, match)) continue;
431
432 idx = script_int(i);
433 nick = script_string(dcc[i].nick, -1);
434 host = script_string(dcc[i].host, -1);
435 type = script_string(dcc[i].type->name, -1);
436 if (dcc[i].type->display) dcc[i].type->display(i, other);
437 else sprintf(other, "?:%X !! ERROR !!", (int) dcc[i].type);
438 othervar = script_string(strdup(other), -1);
439 othervar->type |= SCRIPT_FREE;
440 timestamp = script_int(dcc[i].timeval);
441
442 sublist = script_list(6, idx, nick, host, type, othervar, timestamp);
443 script_list_append(retval, sublist);
444 }
445 return(0);
446 }
447
448 static void whom_entry(script_var_t *retval, char *nick, char *bot, char *host ,char icon, int idletime, char *away, int chan)
449 {
450 script_var_t *sublist, *vnick, *vbot, *vhost, *vflag, *vidle, *vaway, *vchan;
451 char flag[2];
452
453 vnick = script_string(nick, -1);
454 vbot = script_string(bot, -1);
455 vhost = script_string(host, -1);
456
457 flag[0] = icon;
458 flag[1] = 0;
459 vflag = script_string(strdup(flag), 1);
460 vflag->type |= SCRIPT_FREE;
461
462 vidle = script_int((now - idletime) / 60);
463 vaway = script_string(away ? away : "", -1);
464 vchan = script_int(chan);
465
466 sublist = script_list(7, vnick, vbot, vhost, vflag, vidle, vaway, vchan);
467 script_list_append(retval, sublist);
468 }
469
470 /* list of {nick bot host flag idletime awaymsg channel}
471 */
472 static int script_whom(script_var_t *retval, int nargs, int which_chan)
473 {
474 int i;
475
476 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR;
477 retval->len = 0;
478 retval->value = NULL;
479
480 if (nargs == 0) which_chan = -1;
481
482 for (i = 0; i < dcc_total; i++) {
483 if (dcc[i].type != &DCC_CHAT) continue;
484 if (which_chan != -1 && dcc[i].u.chat->channel != which_chan) continue;
485 whom_entry(retval, dcc[i].nick, botnetnick, dcc[i].host,
486 geticon(dcc[i].user), dcc[i].timeval, dcc[i].u.chat->away,
487 dcc[i].u.chat->channel);
488 }
489 for (i = 0; i < parties; i++) {
490 if (which_chan != -1 && party[i].chan != which_chan) continue;
491 whom_entry(retval, party[i].nick, party[i].bot, party[i].from, party[i].flag, party[i].timer, party[i].status & PLSTAT_AWAY ? party[i].away : "", party[i].chan);
492 }
493 return(0);
494 }
495
496 static int script_dccused()
497 {
498 return(dcc_total);
499 }
500
501 static int script_getdccidle(int idx)
502 {
503 if (idx < 0 || idx >= dcc_total || !(dcc->type)) return(-1);
504 return(now - dcc[idx].timeval);
505 }
506
507 static char *script_getdccaway(int idx)
508 {
509 if (idx < 0 || idx >= dcc_total || !(dcc[idx].type) || dcc[idx].type != &DCC_CHAT) return("");
510 if (dcc[idx].u.chat->away == NULL) return("");
511 return(dcc[idx].u.chat->away);
512 }
513
514 static int script_setdccaway(int idx, char *text)
515 {
516 if (idx < 0 || idx >= dcc_total || !(dcc[idx].type) || dcc[idx].type != &DCC_CHAT) return(1);
517 if (!text || !text[0]) {
518 /* un-away */
519 if (dcc[idx].u.chat->away != NULL) not_away(idx);
520 }
521 else set_away(idx, text);
522 return(0);
523 }
524
525 static int script_link(char *via, char *target)
526 {
527 int x, i;
528
529 if (!via) x = botlink("", -2, target);
530 else {
531 x = 1;
532 i = nextbot(via);
533 if (i < 0) x = 0;
534 else botnet_send_link(i, botnetnick, via, target);
535 }
536 return(x);
537 }
538
539 static int script_unlink(char *bot, char *comment)
540 {
541 int i, x;
542
543 i = nextbot(bot);
544 if (i < 0) return(0);
545 if (!strcasecmp(bot, dcc[i].nick)) x = botunlink(-2, bot, comment);
546 else {
547 x = 1;
548 botnet_send_unlink(i, botnetnick, lastbot(bot), bot, comment);
549 }
550 return(x);
551 }
552
553 static int tcl_connect STDVAR
554 {
555 int i, z, sock;
556 char s[81];
557
558 BADARGS(3, 3, " hostname port");
559 if (dcc_total == max_dcc) {
560 Tcl_AppendResult(irp, "out of dcc table space", NULL);
561 return TCL_ERROR;
562 }
563 sock = getsock(0);
564 if (sock < 0) {
565 Tcl_AppendResult(irp, _("No free sockets available."), NULL);
566 return TCL_ERROR;
567 }
568 z = open_telnet_raw(sock, argv[1], atoi(argv[2]));
569 if (z < 0) {
570 killsock(sock);
571 if (z == (-2))
572 strncpyz(s, "DNS lookup failed", sizeof s);
573 else
574 neterror(s);
575 Tcl_AppendResult(irp, s, NULL);
576 return TCL_ERROR;
577 }
578 /* Well well well... it worked! */
579 i = new_dcc(&DCC_SOCKET, 0);
580 dcc[i].sock = sock;
581 dcc[i].port = atoi(argv[2]);
582 strcpy(dcc[i].nick, "*");
583 strncpyz(dcc[i].host, argv[1], UHOSTMAX);
584 snprintf(s, sizeof s, "%d", i);
585 Tcl_AppendResult(irp, s, NULL);
586 return TCL_OK;
587 }
588
589 /* Create a new listening port (or destroy one)
590 *
591 * listen <port> bots/all/users [mask]
592 * listen <port> script <proc> [flag]
593 * listen <port> off
594 */
595 static int tcl_listen STDVAR
596 {
597 int i, j, idx = (-1), port, realport;
598 char s[11];
599 struct portmap *pmap = NULL, *pold = NULL;
600 int af = AF_INET /* af_preferred */;
601
602 BADARGS(3, 6, " ?-4/-6? port type ?mask?/?proc ?flag??");
603 if (!strcmp(argv[1], "-4") || !strcmp(argv[1], "-6")) {
604 if (argv[1][1] == '4')
605 af = AF_INET;
606 else
607 af = AF_INET6;
608 argv[1] = argv[0]; /* UGLY! */
609 argv++;
610 argc--;
611 }
612 BADARGS(3, 6, " ?-4/-6? port type ?mask?/?proc ?flag??");
613
614 port = realport = atoi(argv[1]);
615 for (pmap = root; pmap; pold = pmap, pmap = pmap->next)
616 if (pmap->realport == port) {
617 port = pmap->mappedto;
618 break;
619 }
620 for (i = 0; i < dcc_total; i++)
621 if ((dcc[i].type == &DCC_TELNET) && (dcc[i].port == port))
622 idx = i;
623 if (!strcasecmp(argv[2], "off")) {
624 if (pmap) {
625 if (pold)
626 pold->next = pmap->next;
627 else
628 root = pmap->next;
629 free(pmap);
630 }
631 /* Remove */
632 if (idx < 0) {
633 Tcl_AppendResult(irp, "no such listen port is open", NULL);
634 return TCL_ERROR;
635 }
636 killsock(dcc[idx].sock);
637 lostdcc(idx);
638 return TCL_OK;
639 }
640 if (idx < 0) {
641 /* Make new one */
642 if (dcc_total >= max_dcc) {
643 Tcl_AppendResult(irp, "no more DCC slots available", NULL);
644 return TCL_ERROR;
645 }
646 /* Try to grab port */
647 j = port + 20;
648 i = (-1);
649 while (port < j && i < 0) {
650 i = open_listen(&port, af);
651 if (i == -1)
652 port++;
653 else if (i == -2)
654 break;
655 }
656 if (i == -1) {
657 Tcl_AppendResult(irp, "Couldn't grab nearby port", NULL);
658 return TCL_ERROR;
659 } else if (i == -2) {
660 Tcl_AppendResult(irp, "Couldn't assign the requested IP. Please make sure 'my-ip' and/or 'my-ip6' is set properly.", NULL);
661 return TCL_ERROR;
662 }
663 idx = new_dcc(&DCC_TELNET, 0);
664 strcpy(dcc[idx].addr, "*"); /* who cares? */
665 dcc[idx].port = port;
666 dcc[idx].sock = i;
667 dcc[idx].timeval = now;
668 }
669 /* script? */
670 if (!strcmp(argv[2], "script")) {
671 strcpy(dcc[idx].nick, "(script)");
672 if (argc < 4) {
673 Tcl_AppendResult(irp, "must give proc name for script listen", NULL);
674 killsock(dcc[idx].sock);
675 lostdcc(idx);
676 return TCL_ERROR;
677 }
678 if (argc == 5) {
679 if (strcmp(argv[4], "pub")) {
680 Tcl_AppendResult(irp, "unknown flag: ", argv[4], ". allowed flags: pub",
681 NULL);
682 killsock(dcc[idx].sock);
683 lostdcc(idx);
684 return TCL_ERROR;
685 }
686 dcc[idx].status = LSTN_PUBLIC;
687 }
688 strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
689 snprintf(s, sizeof s, "%d", port);
690 Tcl_AppendResult(irp, s, NULL);
691 return TCL_OK;
692 }
693 /* bots/users/all */
694 if (!strcmp(argv[2], "bots"))
695 strcpy(dcc[idx].nick, "(bots)");
696 else if (!strcmp(argv[2], "users"))
697 strcpy(dcc[idx].nick, "(users)");
698 else if (!strcmp(argv[2], "all"))
699 strcpy(dcc[idx].nick, "(telnet)");
700 if (!dcc[idx].nick[0]) {
701 Tcl_AppendResult(irp, "illegal listen type: must be one of ",
702 "bots, users, all, off, script", NULL);
703 killsock(dcc[idx].sock);
704 dcc_total--;
705 return TCL_ERROR;
706 }
707 if (argc == 4) {
708 strncpyz(dcc[idx].host, argv[3], UHOSTMAX);
709 } else
710 strcpy(dcc[idx].host, "*");
711 snprintf(s, sizeof s, "%d", port);
712 Tcl_AppendResult(irp, s, NULL);
713 if (!pmap) {
714 pmap = malloc(sizeof(struct portmap));
715 pmap->next = root;
716 root = pmap;
717 }
718 pmap->realport = realport;
719 pmap->mappedto = port;
720 putlog(LOG_MISC, "*", "Listening at telnet port %d (%s)", port, argv[2]);
721 return TCL_OK;
722 }
723
724 static int script_boot(char *user_bot, char *reason)
725 {
726 char who[NOTENAMELEN + 1];
727 int i;
728
729 strncpyz(who, user_bot, sizeof who);
730 if (strchr(who, '@') != NULL) {
731 char whonick[HANDLEN + 1];
732
733 splitc(whonick, who, '@');
734 whonick[HANDLEN] = 0;
735 if (!strcasecmp(who, botnetnick))
736 strncpyz(who, whonick, sizeof who);
737 else if (remote_boots > 0) {
738 i = nextbot(who);
739 if (i < 0) return(0);
740 botnet_send_reject(i, botnetnick, NULL, whonick, who, reason ? reason : "");
741 }
742 else return(0);
743 }
744 for (i = 0; i < dcc_total; i++)
745 if ((dcc[i].type) && (dcc[i].type->flags & DCT_CANBOOT) &&
746 !strcasecmp(dcc[i].nick, who)) {
747 do_boot(i, botnetnick, reason ? reason : "");
748 break;
749 }
750 return(0);
751 }
752
753 static int script_rehash()
754 {
755 if (make_userfile) {
756 putlog(LOG_MISC, "*", _("Userfile creation not necessary--skipping"));
757 make_userfile = 0;
758 }
759 write_userfile(-1);
760 putlog(LOG_MISC, "*", _("Rehashing..."));
761 do_restart = -2;
762 return(0);
763 }
764
765 static int script_restart()
766 {
767 if (!backgrd) return(1);
768 if (make_userfile) {
769 putlog(LOG_MISC, "*", _("Userfile creation not necessary--skipping"));
770 make_userfile = 0;
771 }
772 write_userfile(-1);
773 putlog(LOG_MISC, "*", _("Restarting..."));
774 do_restart = -1;
775 return(0);
776 }
777
778 static int tcl_traffic STDVAR
779 {
780 char buf[1024];
781 unsigned long out_total_today, out_total;
782 unsigned long in_total_today, in_total;
783
784 /* IRC traffic */
785 sprintf(buf, "irc %ld %ld %ld %ld", itraffic_irc_today,
786 itraffic_irc + itraffic_irc_today, otraffic_irc_today,
787 otraffic_irc + otraffic_irc_today);
788 Tcl_AppendElement(irp, buf);
789
790 /* Botnet traffic */
791 sprintf(buf, "botnet %ld %ld %ld %ld", itraffic_bn_today,
792 itraffic_bn + itraffic_bn_today, otraffic_bn_today,
793 otraffic_bn + otraffic_bn_today);
794 Tcl_AppendElement(irp, buf);
795
796 /* Partyline */
797 sprintf(buf, "partyline %ld %ld %ld %ld", itraffic_dcc_today,
798 itraffic_dcc + itraffic_dcc_today, otraffic_dcc_today,
799 otraffic_dcc + otraffic_dcc_today);
800 Tcl_AppendElement(irp, buf);
801
802 /* Transfer */
803 sprintf(buf, "transfer %ld %ld %ld %ld", itraffic_trans_today,
804 itraffic_trans + itraffic_trans_today, otraffic_trans_today,
805 otraffic_trans + otraffic_trans_today);
806 Tcl_AppendElement(irp, buf);
807
808 /* Misc traffic */
809 sprintf(buf, "misc %ld %ld %ld %ld", itraffic_unknown_today,
810 itraffic_unknown + itraffic_unknown_today, otraffic_unknown_today,
811 otraffic_unknown + otraffic_unknown_today);
812 Tcl_AppendElement(irp, buf);
813
814 /* Totals */
815 in_total_today = itraffic_irc_today + itraffic_bn_today + itraffic_dcc_today
816 + itraffic_trans_today + itraffic_unknown_today,
817 in_total = in_total_today + itraffic_irc + itraffic_bn + itraffic_dcc
818 + itraffic_trans + itraffic_unknown;
819 out_total_today = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
820 + itraffic_trans_today + otraffic_unknown_today,
821 out_total = out_total_today + otraffic_irc + otraffic_bn + otraffic_dcc
822 + otraffic_trans + otraffic_unknown;
823 sprintf(buf, "total %ld %ld %ld %ld",
824 in_total_today, in_total, out_total_today, out_total);
825 Tcl_AppendElement(irp, buf);
826 return(TCL_OK);
827 }
828
829 script_simple_command_t script_dcc_cmds[] = {
830 {"", NULL, NULL, NULL, 0},
831 {"putdcc", script_putdcc, "is", "idx text", SCRIPT_INTEGER},
832 {"putdccraw", script_putdccraw, "iis", "idx len text", SCRIPT_INTEGER},
833 {"dccsimul", script_dccsimul, "is", "idx command", SCRIPT_INTEGER},
834 {"dccbroadcast", script_dccbroadcast, "s", "text", SCRIPT_INTEGER},
835 {"hand2idx", script_hand2idx, "s", "handle", SCRIPT_INTEGER},
836 {"getchan", script_getchan, "i", "idx", SCRIPT_INTEGER},
837 {"setchan", script_setchan, "ii", "idx chan", SCRIPT_INTEGER},
838 {"dccputchan", script_dccputchan, "is", "chan text", SCRIPT_INTEGER},
839 {"valididx", script_valididx, "i", "idx", SCRIPT_INTEGER},
840 {"putbot", script_putbot, "ss", "bot text", SCRIPT_INTEGER},
841 {"putallbots", script_putallbots, "s", "text", SCRIPT_INTEGER},
842 {"idx2hand", (Function) script_idx2hand, "i", "idx", SCRIPT_INTEGER},
843 {"islinked", script_islinked, "s", "bot", SCRIPT_INTEGER},
844 {"dccused", script_dccused, "", "", SCRIPT_INTEGER},
845 {"getdccidle", script_getdccidle, "i", "idx", SCRIPT_INTEGER},
846 {"getdccaway", (Function) script_getdccaway, "i", "idx", SCRIPT_STRING},
847 {"setdccaway", script_setdccaway, "is", "idx msg", SCRIPT_INTEGER},
848 {"unlink", script_unlink, "ss", "bot comment", SCRIPT_INTEGER},
849 {"boot", script_boot, "ss", "user@bot reason", SCRIPT_INTEGER},
850 {"rehash", script_rehash, "", "", SCRIPT_INTEGER},
851 {"restart", script_restart, "", "", SCRIPT_INTEGER},
852 {0}
853 };
854
855 script_command_t script_full_dcc_cmds[] = {
856 {"", "console", script_console, NULL, 1, "is", "idx ?changes?", 0, SCRIPT_PASS_RETVAL|SCRIPT_PASS_COUNT|SCRIPT_VAR_ARGS},
857 {"", "strip", script_strip, NULL, 1, "is", "idx ?change?", 0, SCRIPT_PASS_RETVAL|SCRIPT_PASS_COUNT|SCRIPT_VAR_ARGS},
858 {"", "echo", script_echo, NULL, 1, "ii", "idx ?status?", SCRIPT_INTEGER, SCRIPT_PASS_COUNT|SCRIPT_VAR_ARGS},
859 {"", "page", script_page, NULL, 1, "ii", "idx ?status?", SCRIPT_INTEGER, SCRIPT_PASS_COUNT|SCRIPT_VAR_ARGS},
860 {"", "bots", script_bots, NULL, 0, "", "", 0, SCRIPT_PASS_RETVAL},
861 {"", "botlist", script_botlist, NULL, 0, "", "", 0, SCRIPT_PASS_RETVAL},
862 {"", "dcclist", script_dcclist, NULL, 0, "s", "?match?", 0, SCRIPT_PASS_RETVAL|SCRIPT_VAR_ARGS},
863 {"", "link", script_link, NULL, 1, "ss", "?via-bot? target-bot", 0, SCRIPT_VAR_ARGS | SCRIPT_VAR_FRONT},
864 {"", "whom", script_whom, NULL, 0, "i", "?channel?", 0, SCRIPT_PASS_RETVAL|SCRIPT_PASS_COUNT|SCRIPT_VAR_ARGS},
865 {0}
866 };
867
868 tcl_cmds tcldcc_cmds[] =
869 {
870 {"control", tcl_control},
871 {"killdcc", tcl_killdcc},
872 {"connect", tcl_connect},
873 {"listen", tcl_listen},
874 {"traffic", tcl_traffic},
875 {NULL, NULL}
876 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23