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

Annotation of /eggdrop1.4/src/botcmd.c

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


Revision 1.12 - (hide annotations) (download) (as text)
Wed Dec 22 20:30:03 1999 UTC (20 years, 3 months ago) by guppy
Branch: MAIN
Changes since 1.11: +2 -2 lines
File MIME type: text/x-chdr
patches .. and more patches

1 guppy 1.10 /*
2     * botcmd.c -- handles:
3     * commands that comes across the botnet
4     * userfile transfer and update commands from sharebots
5 segfault 1.1 *
6 guppy 1.10 * dprintf'ized, 10nov1995
7     *
8 guppy 1.12 * $Id: botcmd.c,v 1.11 1999/12/16 04:03:46 guppy Exp $
9 segfault 1.1 */
10 guppy 1.10 /*
11     * Copyright (C) 1997 Robey Pointer
12     * Copyright (C) 1999 Eggheads
13     *
14     * This program is free software; you can redistribute it and/or
15     * modify it under the terms of the GNU General Public License
16     * as published by the Free Software Foundation; either version 2
17     * of the License, or (at your option) any later version.
18     *
19     * This program is distributed in the hope that it will be useful,
20     * but WITHOUT ANY WARRANTY; without even the implied warranty of
21     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22     * GNU General Public License for more details.
23     *
24     * You should have received a copy of the GNU General Public License
25     * along with this program; if not, write to the Free Software
26     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 segfault 1.1 */
28    
29     #include "main.h"
30     #include "tandem.h"
31     #include "users.h"
32     #include "chan.h"
33     #include "modules.h"
34    
35     extern struct dcc_t *dcc;
36     extern char botnetnick[];
37     extern struct chanset_t *chanset;
38     extern int dcc_total;
39     extern char ver[];
40     extern char admin[];
41     extern Tcl_Interp *interp;
42     extern time_t now, online_since;
43     extern char network[];
44     extern struct userrec *userlist;
45     extern int remote_boots;
46     extern char motdfile[];
47     extern party_t *party;
48     extern int noshare;
49     extern module_entry *module_list;
50    
51     static char TBUF[1024]; /* static buffer for goofy bot stuff */
52    
53     static char base64to[256] =
54     {
55     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57     0, 0, 0, 0, 0, 0, 0, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0,
58     0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
59     15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 62, 0, 63, 0, 0, 0, 26, 27, 28,
60     29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
61     49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
68     };
69    
70     int base64_to_int(char *buf)
71     {
72     int i = 0;
73    
74     while (*buf) {
75     i = i << 6;
76     i += base64to[(int) *buf];
77     buf++;
78     }
79     return i;
80 poptix 1.5 }
81 segfault 1.1
82     /* used for 1.0 compatibility: if a join message arrives with no sock#, */
83     /* i'll just grab the next "fakesock" # (incrementing to assure uniqueness) */
84     static int fakesock = 2300;
85    
86     static void fake_alert(int idx, char *item, char *extra)
87     {
88     #ifndef NO_OLD_BOTNET
89     if (b_numver(idx) < NEAT_BOTNET)
90     dprintf(idx, "chat %s NOTICE: %s (%s != %s).\n",
91     botnetnick, NET_FAKEREJECT, item, extra);
92     else
93     #endif
94     dprintf(idx, "ct %s NOTICE: %s (%s != %s).\n",
95     botnetnick, NET_FAKEREJECT, item, extra);
96     putlog(LOG_BOTS, "*", "%s %s (%s != %s).", dcc[idx].nick, NET_FAKEREJECT,
97     item, extra);
98     }
99    
100     /* chan <from> <chan> <text> */
101     static void bot_chan2(int idx, char *msg)
102     {
103     char *from, *p;
104     int i, chan;
105    
106 guppy 1.9 Context;
107 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
108     return;
109     from = newsplit(&msg);
110     p = newsplit(&msg);
111     #ifndef NO_OLD_BOTNET
112     if (b_numver(idx) < NEAT_BOTNET)
113     chan = atoi(p);
114     else
115     #endif
116     chan = base64_to_int(p);
117     /* strip annoying control chars */
118     for (p = from; *p;) {
119     if ((*p < 32) || (*p == 127))
120     strcpy(p, p + 1);
121     else
122     p++;
123     }
124     p = strchr(from, '@');
125     if (p) {
126     sprintf(TBUF, "<%s> %s", from, msg);
127     *p = 0;
128     if (!partyidle(p + 1, from)) {
129     *p = '@';
130     fake_alert(idx, "user", from);
131     return;
132     }
133     *p = '@';
134     p++;
135     } else {
136     sprintf(TBUF, "*** (%s) %s", from, msg);
137     p = from;
138     }
139     i = nextbot(p);
140     if (i != idx) {
141     fake_alert(idx, "direction", p);
142     } else {
143     chanout_but(-1, chan, "%s\n", TBUF);
144     /* send to new version bots */
145 guppy 1.11 if (i >= 0)
146     botnet_send_chan(idx, from, NULL, chan, msg);
147 segfault 1.1 if (strchr(from, '@') != NULL)
148     check_tcl_chat(from, chan, msg);
149     else
150     check_tcl_bcst(from, chan, msg);
151     }
152     }
153    
154     /* chat <from> <notice> -- only from bots */
155     static void bot_chat(int idx, char *par)
156     {
157     char *from;
158     int i;
159    
160 guppy 1.9 Context;
161 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
162     return;
163     from = newsplit(&par);
164     if (strchr(from, '@') != NULL) {
165     fake_alert(idx, "bot", from);
166     return;
167     }
168     /* make sure the bot is valid */
169     i = nextbot(from);
170     if (i != idx) {
171     fake_alert(idx, "direction", from);
172     return;
173     }
174     chatout("*** (%s) %s\n", from, par);
175     botnet_send_chat(idx, from, par);
176     }
177    
178     /* actchan <from> <chan> <text> */
179     static void bot_actchan(int idx, char *par)
180     {
181     char *from, *p;
182     int i, chan;
183    
184 guppy 1.9 Context;
185 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
186     return;
187     from = newsplit(&par);
188     p = strchr(from, '@');
189     if (p == NULL) {
190     /* how can a bot do an action? */
191     fake_alert(idx, "user@bot", from);
192     return;
193     }
194     *p = 0;
195     if (!partyidle(p + 1, from)) {
196     *p = '@';
197     fake_alert(idx, "user", from);
198     }
199     *p = '@';
200     p++;
201     i = nextbot(p);
202     if (i != idx) {
203     fake_alert(idx, "direction", p);
204     return;
205     }
206     p = newsplit(&par);
207     #ifndef NO_OLD_BOTNET
208     if (b_numver(idx) < NEAT_BOTNET)
209     chan = atoi(p);
210     else
211     #endif
212     chan = base64_to_int(p);
213     for (p = from; *p;) {
214     if ((*p < 32) || (*p == 127))
215     strcpy(p, p + 1);
216     else
217     p++;
218     }
219     chanout_but(-1, chan, "* %s %s\n", from, par);
220     botnet_send_act(idx, from, NULL, chan, par);
221     check_tcl_act(from, chan, par);
222     }
223    
224     /* priv <from> <to> <message> */
225     static void bot_priv(int idx, char *par)
226     {
227     char *from, *p, *to = TBUF, *tobot;
228     int i;
229    
230 guppy 1.9 Context;
231 segfault 1.1 from = newsplit(&par);
232     tobot = newsplit(&par);
233     splitc(to, tobot, '@');
234     p = strchr(from, '@');
235     if (p != NULL)
236     p++;
237     else
238     p = from;
239     i = nextbot(p);
240     if (i != idx) {
241     fake_alert(idx, "direction", p);
242     return;
243     }
244     if (!to[0])
245     return; /* silently ignore notes to '@bot' this
246     * is legacy code */
247     if (!strcasecmp(tobot, botnetnick)) { /* for me! */
248     if (p == from)
249     add_note(to, from, par, -2, 0);
250     else {
251     i = add_note(to, from, par, -1, 0);
252     if (from[0] != '@')
253     switch (i) {
254     case NOTE_ERROR:
255     botnet_send_priv(idx, botnetnick, from, NULL,
256     "%s %s.", BOT_NOSUCHUSER, to);
257     break;
258     case NOTE_STORED:
259     botnet_send_priv(idx, botnetnick, from, NULL,
260     "%s", BOT_NOTESTORED2);
261     break;
262     case NOTE_FULL:
263     botnet_send_priv(idx, botnetnick, from, NULL,
264     "%s", BOT_NOTEBOXFULL);
265     break;
266     case NOTE_AWAY:
267     botnet_send_priv(idx, botnetnick, from, NULL,
268     "%s %s", to, BOT_NOTEISAWAY);
269     break;
270     case NOTE_FWD:
271     botnet_send_priv(idx, botnetnick, from, NULL,
272     "%s %s", "Not online; note forwarded to:", to);
273     break;
274 poptix 1.4 case NOTE_REJECT:
275     botnet_send_priv(idx, botnetnick, from, NULL,
276     "%s %s", to, "rejected your note.");
277     break;
278 segfault 1.1 case NOTE_TCL:
279     break; /* do nothing */
280     case NOTE_OK:
281     botnet_send_priv(idx, botnetnick, from, NULL,
282     "%s %s.", BOT_NOTESENTTO, to);
283     break;
284     }
285     }
286     } else { /* pass it on */
287     i = nextbot(tobot);
288     if (i >= 0)
289     botnet_send_priv(i, from, to, tobot, "%s", par);
290     }
291     }
292    
293     static void bot_bye(int idx, char *par)
294     {
295     char s[1024];
296    
297 guppy 1.9 Context;
298 segfault 1.1 simple_sprintf(s, "%s %s. %s", BOT_DISCONNECTED, dcc[idx].nick, par);
299     putlog(LOG_BOTS, "*", "%s", s);
300     chatout("*** %s\n", s);
301     botnet_send_unlinked(idx, dcc[idx].nick, s);
302     dprintf(idx, "*bye\n");
303     killsock(dcc[idx].sock);
304     lostdcc(idx);
305     }
306    
307     static void remote_tell_who(int idx, char *nick, int chan)
308     {
309     int i = 10, k, l, ok = 0;
310     char s[1024];
311     struct chanset_t *c;
312    
313 guppy 1.9 Context;
314 segfault 1.1 strcpy(s, "Channels: ");
315     c = chanset;
316     while (c != NULL) {
317     if (!channel_secret(c)) {
318     l = strlen(c->name);
319     if (i + l < 1021) {
320     if (i > 10) {
321     s[i++] = ',';
322     s[i++] = ' ';
323     }
324     strcpy(s + i, c->name);
325     i += (l + 2);
326     }
327     }
328     c = c->next;
329     }
330     if (i > 10) {
331     botnet_send_priv(idx, botnetnick, nick, NULL, "%s (%s)", s, ver);
332     } else
333     botnet_send_priv(idx, botnetnick, nick, NULL, "%s (%s)", BOT_NOCHANNELS, ver);
334     if (admin[0])
335     botnet_send_priv(idx, botnetnick, nick, NULL, "Admin: %s", admin);
336     if (chan == 0)
337     botnet_send_priv(idx, botnetnick, nick, NULL,
338     "%s (* = %s, + = %s, @ = %s)",
339     BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
340     else {
341     simple_sprintf(s, "assoc %d", chan);
342     if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
343     botnet_send_priv(idx, botnetnick, nick, NULL,
344     "%s %s%d: (* = %s, + = %s, @ = %s)\n",
345     BOT_PEOPLEONCHAN,
346     (chan < GLOBAL_CHANS) ? "" : "*",
347     chan % GLOBAL_CHANS,
348     MISC_OWNER, MISC_MASTER, MISC_OP);
349     else
350     botnet_send_priv(idx, botnetnick, nick, NULL,
351     "%s '%s' (%s%d): (* = %s, + = %s, @ = %s)\n",
352     BOT_PEOPLEONCHAN, interp->result,
353     (chan < 100000) ? "" : "*", chan % 100000,
354     MISC_OWNER, MISC_MASTER, MISC_OP);
355     }
356     for (i = 0; i < dcc_total; i++)
357     if (dcc[i].type->flags & DCT_REMOTEWHO)
358     if (dcc[i].u.chat->channel == chan) {
359     k = sprintf(s, " %c%-15s %s",
360     (geticon(i) == '-' ? ' ' : geticon(i)),
361     dcc[i].nick, dcc[i].host);
362     if (now - dcc[i].timeval > 300) {
363     unsigned long days, hrs, mins;
364    
365     days = (now - dcc[i].timeval) / 86400;
366     hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
367     mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
368     if (days > 0)
369     sprintf(s + k, " (%s %lud%luh)",
370     MISC_IDLE, days, hrs);
371     else if (hrs > 0)
372     sprintf(s + k, " (%s %luh%lum)",
373     MISC_IDLE, hrs, mins);
374     else
375     sprintf(s + k, " (%s %lum)",
376     MISC_IDLE, mins);
377     }
378     botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
379     if (dcc[i].u.chat->away != NULL)
380     botnet_send_priv(idx, botnetnick, nick, NULL, " %s: %s",
381     MISC_AWAY, dcc[i].u.chat->away);
382     }
383     for (i = 0; i < dcc_total; i++)
384     if (dcc[i].type == &DCC_BOT) {
385     if (!ok) {
386     ok = 1;
387     botnet_send_priv(idx, botnetnick, nick, NULL,
388     "%s:", BOT_BOTSCONNECTED);
389     }
390     sprintf(s, " %s%c%-15s %s",
391     dcc[i].status & STAT_CALLED ? "<-" : "->",
392     dcc[i].status & STAT_SHARE ? '+' : ' ',
393     dcc[i].nick, dcc[i].u.bot->version);
394     botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
395     }
396     ok = 0;
397     for (i = 0; i < dcc_total; i++)
398     if (dcc[i].type->flags & DCT_REMOTEWHO)
399     if (dcc[i].u.chat->channel != chan) {
400     if (!ok) {
401     ok = 1;
402     botnet_send_priv(idx, botnetnick, nick, NULL, "%s:",
403     BOT_OTHERPEOPLE);
404     }
405     l = sprintf(s, " %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)),
406     dcc[i].nick, dcc[i].host);
407     if (now - dcc[i].timeval > 300) {
408     k = (now - dcc[i].timeval) / 60;
409     if (k < 60)
410     sprintf(s + l, " (%s %dm)", MISC_IDLE, k);
411     else
412     sprintf(s + l, " (%s %dh%dm)", MISC_IDLE, k / 60, k % 60);
413     }
414     botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
415     if (dcc[i].u.chat->away != NULL)
416     botnet_send_priv(idx, botnetnick, nick, NULL,
417     " %s: %s", MISC_AWAY,
418     dcc[i].u.chat->away);
419     }
420     }
421    
422     /* who <from@bot> <tobot> <chan#> */
423     static void bot_who(int idx, char *par)
424     {
425     char *from, *to, *p;
426     int i, chan;
427    
428 guppy 1.9 Context;
429 segfault 1.1 from = newsplit(&par);
430     p = strchr(from, '@');
431     if (!p) {
432     sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
433     from = TBUF;
434     }
435     to = newsplit(&par);
436     if (!strcasecmp(to, botnetnick))
437     to[0] = 0; /* (for me) */
438     #ifndef NO_OLD_BOTNET
439     if (b_numver(idx) < NEAT_BOTNET)
440     chan = atoi(par);
441     else
442     #endif
443     chan = base64_to_int(par);
444     if (to[0]) { /* pass it on */
445     i = nextbot(to);
446     if (i >= 0)
447     botnet_send_who(i, from, to, chan);
448     } else {
449     remote_tell_who(idx, from, chan);
450     }
451     }
452    
453     static void bot_endlink(int idx, char *par)
454     {
455     dcc[idx].status &= ~STAT_LINKING;
456     }
457    
458     /* info? <from@bot> -> send priv */
459     static void bot_infoq(int idx, char *par)
460     {
461 poptix 1.3 char s[200], s2[32];
462 segfault 1.1 struct chanset_t *chan;
463     time_t now2;
464     int hr, min;
465    
466 guppy 1.9 Context;
467 segfault 1.1 chan = chanset;
468     now2 = now - online_since;
469     s2[0] = 0;
470     if (now2 > 86400) {
471     int days = now2 / 86400;
472    
473     /* days */
474     sprintf(s2, "%d day", days);
475     if (days >= 2)
476     strcat(s2, "s");
477     strcat(s2, ", ");
478     now2 -= days * 86400;
479     }
480     hr = (time_t) ((int) now2 / 3600);
481     now2 -= (hr * 3600);
482     min = (time_t) ((int) now2 / 60);
483     sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
484     if (module_find("server", 0, 0)) {
485     s[0] = 0;
486     while (chan != NULL) {
487     if (!channel_secret(chan)) {
488 poptix 1.3 if ((strlen(s) + strlen(chan->name) + strlen(network)
489     + strlen(botnetnick) + strlen(ver) + 1) >= 200) {
490     strcat(s,"++ ");
491     break; /* yegads..! */
492     }
493 segfault 1.1 strcat(s, chan->name);
494     strcat(s, ", ");
495     }
496     chan = chan->next;
497     }
498     if (s[0]) {
499     s[strlen(s) - 2] = 0;
500     botnet_send_priv(idx, botnetnick, par, NULL,
501     "%s <%s> (%s) [UP %s]", ver, network, s, s2);
502     } else
503     botnet_send_priv(idx, botnetnick, par, NULL,
504     "%s <%s> (%s) [UP %s]", ver, network, BOT_NOCHANNELS,
505     s2);
506     } else
507     botnet_send_priv(idx, botnetnick, par, NULL,
508     "%s <NO_IRC> [UP %s]", ver, s2);
509     botnet_send_infoq(idx, par);
510     }
511    
512     static void bot_ping(int idx, char *par)
513     {
514 guppy 1.9 Context;
515 segfault 1.1 botnet_send_pong(idx);
516     }
517    
518     static void bot_pong(int idx, char *par)
519     {
520 guppy 1.9 Context;
521 segfault 1.1 dcc[idx].status &= ~STAT_PINGED;
522     }
523    
524     /* link <from@bot> <who> <to-whom> */
525     static void bot_link(int idx, char *par)
526     {
527     char *from, *bot, *rfrom;
528     int i;
529    
530 guppy 1.9 Context;
531 segfault 1.1 from = newsplit(&par);
532     bot = newsplit(&par);
533    
534     if (!strcasecmp(bot, botnetnick)) {
535     if ((rfrom = strchr(from, ':')))
536     rfrom++;
537     else
538     rfrom = from;
539     putlog(LOG_CMDS, "*", "#%s# link %s", rfrom, par);
540     if (botlink(from, -1, par))
541     botnet_send_priv(idx, botnetnick, from, NULL, "%s %s ...",
542     BOT_LINKATTEMPT, par);
543     else
544     botnet_send_priv(idx, botnetnick, from, NULL, "%s.",
545     BOT_CANTLINKTHERE);
546     } else {
547     i = nextbot(bot);
548     if (i >= 0)
549     botnet_send_link(i, from, bot, par);
550     }
551     }
552    
553     /* unlink <from@bot> <linking-bot> <undesired-bot> <reason> */
554     static void bot_unlink(int idx, char *par)
555     {
556     char *from, *bot, *rfrom, *p, *undes;
557     int i;
558    
559 guppy 1.9 Context;
560 segfault 1.1 from = newsplit(&par);
561     bot = newsplit(&par);
562     undes = newsplit(&par);
563     if (!strcasecmp(bot, botnetnick)) {
564     if ((rfrom = strchr(from, ':')))
565     rfrom++;
566     else
567     rfrom = from;
568     putlog(LOG_CMDS, "*", "#%s# unlink %s (%s)", rfrom, undes, par[0] ? par :
569     "No reason");
570     i = botunlink(-3, undes, par[0] ? par : NULL);
571     if (i == 1) {
572     p = strchr(from, '@');
573     if (p) {
574     /* idx will change after unlink -- get new idx */
575     i = nextbot(p + 1);
576     if (i >= 0)
577     botnet_send_priv(i, botnetnick, from, NULL,
578     "Unlinked from %s.", undes);
579     }
580     } else if (i == 0) {
581     botnet_send_unlinked(-1, undes, "");
582     p = strchr(from, '@');
583     if (p) {
584     /* ditto above, about idx */
585     i = nextbot(p + 1);
586     if (i >= 0)
587     botnet_send_priv(i, botnetnick, from, NULL,
588     "%s %s.", BOT_CANTUNLINK, undes);
589     }
590     } else {
591     p = strchr(from, '@');
592     if (p) {
593     i = nextbot(p + 1);
594     if (i >= 0)
595     botnet_send_priv(i, botnetnick, from, NULL,
596     "Can't remotely unlink sharebots.");
597     }
598     }
599     } else {
600     i = nextbot(bot);
601     if (i >= 0)
602     botnet_send_unlink(i, from, bot, undes, par);
603     }
604     }
605    
606     /* bot next share? */
607     static void bot_update(int idx, char *par)
608     {
609     char *bot, x;
610     int vnum;
611    
612 guppy 1.9 Context;
613 segfault 1.1 bot = newsplit(&par);
614     x = par[0];
615     if (x)
616     par++;
617     #ifndef NO_OLD_BOTNET
618     if (b_numver(idx) < NEAT_BOTNET)
619     vnum = atoi(par);
620     else
621     #endif
622     vnum = base64_to_int(par);
623     if (in_chain(bot))
624     updatebot(idx, bot, x, vnum);
625     }
626    
627     /* newbot next share? */
628     static void bot_nlinked(int idx, char *par)
629     {
630     char *newbot, *next, *p, s[1024], x;
631     int bogus = 0, i;
632     struct userrec *u;
633    
634 guppy 1.9 Context;
635 segfault 1.1 newbot = newsplit(&par);
636     next = newsplit(&par);
637     s[0] = 0;
638     if (!next[0]) {
639     putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)",
640     dcc[idx].nick);
641     simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
642     MISC_INVALIDBOT);
643     dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
644     } else if ((in_chain(newbot)) || (!strcasecmp(newbot, botnetnick))) {
645     /* loop! */
646     putlog(LOG_BOTS, "*", "%s %s (mutual: %s)",
647     BOT_LOOPDETECT, dcc[idx].nick, newbot);
648     simple_sprintf(s, "%s (%s): %s %s", MISC_LOOP, newbot, MISC_DISCONNECTED,
649     dcc[idx].nick);
650     dprintf(idx, "error Loop (%s)\n", newbot);
651     }
652     if (!s[0]) {
653     for (p = newbot; *p; p++)
654     if ((*p < 32) || (*p == 127) || ((p - newbot) >= HANDLEN))
655     bogus = 1;
656     i = nextbot(next);
657     if (i != idx)
658     bogus = 1;
659     }
660     if (bogus) {
661     putlog(LOG_BOTS, "*", "%s %s! (%s -> %s)", BOT_BOGUSLINK, dcc[idx].nick,
662     next, newbot);
663     simple_sprintf(s, "%s: %s %s", BOT_BOGUSLINK, dcc[idx].nick,
664     MISC_DISCONNECTED);
665     dprintf(idx, "error %s (%s -> %s)\n",
666     BOT_BOGUSLINK, next, newbot);
667     }
668     /* beautiful huh? :) */
669     if (bot_flags(dcc[idx].user) & BOT_LEAF) {
670     putlog(LOG_BOTS, "*", "%s %s (%s %s)",
671     BOT_DISCONNLEAF, dcc[idx].nick, newbot,
672     BOT_LINKEDTO);
673     simple_sprintf(s, "%s %s (to %s): %s",
674     BOT_ILLEGALLINK, dcc[idx].nick, newbot,
675     MISC_DISCONNECTED);
676     dprintf(idx, "error %s\n", BOT_YOUREALEAF);
677     }
678     if (s[0]) {
679     chatout("*** %s\n", s);
680     botnet_send_unlinked(idx, dcc[idx].nick, s);
681     dprintf(idx, "bye\n");
682     killsock(dcc[idx].sock);
683     lostdcc(idx);
684     return;
685     }
686     x = par[0];
687     if (x)
688     par++;
689     else
690     x = '-';
691     #ifndef NO_OLD_BOTNET
692     if (b_numver(idx) < NEAT_BOTNET)
693     i = atoi(par);
694     else
695     #endif
696     i = base64_to_int(par);
697     botnet_send_nlinked(idx, newbot, next, x, i);
698     if (x == '!') {
699     chatout("*** (%s) %s %s.\n", next, NET_LINKEDTO, newbot);
700     x = '-';
701     }
702     addbot(newbot, dcc[idx].nick, next, x, i);
703     check_tcl_link(newbot, next);
704     u = get_user_by_handle(userlist, newbot);
705     if (bot_flags(u) & BOT_REJECT) {
706     botnet_send_reject(idx, botnetnick, NULL, newbot, NULL, NULL);
707     putlog(LOG_BOTS, "*", "%s %s %s %s", BOT_REJECTING,
708     newbot, MISC_FROM, dcc[idx].nick);
709     }
710     }
711    
712     #ifndef NO_OLD_BOTNET
713     static void bot_linked(int idx, char *par)
714     {
715     char s[1024];
716    
717 guppy 1.9 Context;
718 segfault 1.1 putlog(LOG_BOTS, "*", "%s", BOT_OLDBOT);
719     simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED,
720     dcc[idx].nick, MISC_OUTDATED);
721     chatout("*** %s\n", s);
722     botnet_send_unlinked(idx, dcc[idx].nick, s);
723     killsock(dcc[idx].sock);
724     lostdcc(idx);
725     }
726    
727     #endif
728    
729     static void bot_unlinked(int idx, char *par)
730     {
731     int i;
732     char *bot;
733    
734 guppy 1.9 Context;
735 segfault 1.1 bot = newsplit(&par);
736     i = nextbot(bot);
737     if ((i >= 0) && (i != idx)) /* bot is NOT downstream along idx, so
738     * BOGUS! */
739     fake_alert(idx, "direction", bot);
740     else if (i >= 0) { /* valid bot downstream of idx */
741     if (par[0])
742     chatout("*** (%s) %s\n", lastbot(bot), par);
743     botnet_send_unlinked(idx, bot, par);
744     unvia(idx, findbot(bot));
745     rembot(bot);
746     }
747     /* otherwise it's not even a valid bot, so just ignore! */
748     }
749    
750     static void bot_trace(int idx, char *par)
751     {
752     char *from, *dest;
753     int i;
754    
755     /* trace <from@bot> <dest> <chain:chain..> */
756 guppy 1.9 Context;
757 segfault 1.1 from = newsplit(&par);
758     dest = newsplit(&par);
759     simple_sprintf(TBUF, "%s:%s", par, botnetnick);
760     botnet_send_traced(idx, from, TBUF);
761     if (strcasecmp(dest, botnetnick) && ((i = nextbot(dest)) > 0))
762     botnet_send_trace(i, from, dest, par);
763     }
764    
765     static void bot_traced(int idx, char *par)
766     {
767     char *to, *p;
768     int i, sock;
769    
770     /* traced <to@bot> <chain:chain..> */
771 guppy 1.9 Context;
772 segfault 1.1 to = newsplit(&par);
773     p = strchr(to, '@');
774     if (p == NULL)
775     p = to;
776     else {
777     *p = 0;
778     p++;
779     }
780     if (!strcasecmp(p, botnetnick)) {
781     time_t t = 0;
782     char *p = par, *ss = TBUF;
783    
784     splitc(ss, to, ':');
785     if (ss[0])
786     sock = atoi(ss);
787     else
788     sock = (-1);
789     if (par[0] == ':') {
790     t = atoi(par + 1);
791     p = strchr(par + 1, ':');
792     if (p)
793     p++;
794     else
795     p = par + 1;
796     }
797     for (i = 0; i < dcc_total; i++)
798     if ((dcc[i].type->flags & DCT_CHAT) &&
799     (!strcasecmp(dcc[i].nick, to)) &&
800     ((sock == (-1)) || (sock == dcc[i].sock))) {
801     if (t) {
802     dprintf(i, "%s -> %s (%lu secs)\n", BOT_TRACERESULT, p, now - t);
803     } else
804     dprintf(i, "%s -> %s\n", BOT_TRACERESULT, p);
805     }
806     } else {
807     i = nextbot(p);
808     if (p != to)
809     *--p = '@';
810     if (i >= 0)
811     botnet_send_traced(i, to, par);
812     }
813     }
814    
815     /* reject <from> <bot> */
816     static void bot_reject(int idx, char *par)
817     {
818     char *from, *who, *destbot, *frombot;
819     struct userrec *u;
820     int i;
821    
822 guppy 1.9 Context;
823 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
824     return;
825     from = newsplit(&par);
826     frombot = strchr(from, '@');
827     if (frombot)
828     frombot++;
829     else
830     frombot = from;
831     i = nextbot(frombot);
832     if (i != idx) {
833     fake_alert(idx, "direction", frombot);
834     return;
835     }
836     who = newsplit(&par);
837     if (!(destbot = strchr(who, '@'))) {
838     /* rejecting a bot */
839     i = nextbot(who);
840     if (i < 0) {
841     botnet_send_priv(idx, botnetnick, from, NULL, "%s %s (%s)",
842     BOT_CANTUNLINK, who, BOT_DOESNTEXIST);
843     } else if (!strcasecmp(dcc[i].nick, who)) {
844     char s[1024];
845    
846     /* i'm the connection to the rejected bot */
847     putlog(LOG_BOTS, "*", "%s %s %s", from, MISC_REJECTED, dcc[i].nick);
848     dprintf(i, "bye\n");
849     simple_sprintf(s, "%s %s (%s: %s)",
850     MISC_DISCONNECTED, dcc[i].nick, from,
851     par[0] ? par : MISC_REJECTED);
852     chatout("*** %s\n", s);
853     botnet_send_unlinked(i, dcc[i].nick, s);
854     killsock(dcc[i].sock);
855     lostdcc(i);
856     } else {
857     if (i >= 0)
858     botnet_send_reject(i, from, NULL, who, NULL, par);
859     }
860     } else { /* rejecting user */
861     *destbot++ = 0;
862     if (!strcasecmp(destbot, botnetnick)) {
863     /* kick someone here! */
864     int ok = 0;
865    
866     if (remote_boots == 1) {
867     frombot = strchr(from, '@');
868     if (frombot == NULL)
869     frombot = from;
870     else
871     frombot++;
872     u = get_user_by_handle(userlist, frombot);
873     if (!(bot_flags(u) & BOT_SHARE)) {
874     add_note(from, botnetnick, "No non sharebot boots.", -1, 0);
875     ok = 1;
876     }
877     } else if (remote_boots == 0) {
878     botnet_send_priv(idx, botnetnick, from, NULL, "%s",
879     BOT_NOREMOTEBOOT);
880     ok = 1;
881     }
882     for (i = 0; (i < dcc_total) && (!ok); i++)
883     if ((!strcasecmp(who, dcc[i].nick)) &&
884     (dcc[i].type->flags & DCT_CHAT)) {
885     u = get_user_by_handle(userlist, dcc[i].nick);
886     if (u && (u->flags & USER_OWNER)) {
887     add_note(from, botnetnick, BOT_NOOWNERBOOT, -1, 0);
888     return;
889     }
890     do_boot(i, from, par);
891     ok = 1;
892     putlog(LOG_CMDS, "*", "#%s# boot %s (%s)", from, dcc[i].nick, par);
893     }
894     } else {
895     i = nextbot(destbot);
896     *--destbot = '@';
897     if (i >= 0)
898     botnet_send_reject(i, from, NULL, who, NULL, par);
899     }
900     }
901     }
902    
903     static void bot_thisbot(int idx, char *par)
904     {
905 guppy 1.9 Context;
906 segfault 1.1 if (strcasecmp(par, dcc[idx].nick) != 0) {
907     char s[1024];
908    
909     putlog(LOG_BOTS, "*", NET_WRONGBOT, dcc[idx].nick, par);
910     dprintf(idx, "bye\n");
911     simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
912     MISC_IMPOSTER);
913     chatout("*** %s\n", s);
914     botnet_send_unlinked(idx, dcc[idx].nick, s);
915     unvia(idx, findbot(dcc[idx].nick));
916     killsock(dcc[idx].sock);
917     lostdcc(idx);
918     return;
919     }
920     if (bot_flags(dcc[idx].user) & BOT_LEAF)
921     dcc[idx].status |= STAT_LEAF;
922     /* set capitalization the way they want it */
923     noshare = 1;
924     change_handle(dcc[idx].user, par);
925     noshare = 0;
926     strcpy(dcc[idx].nick, par);
927     }
928    
929     static void bot_handshake(int idx, char *par)
930     {
931     struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick);
932    
933     /* only set a new password if no old one exists */
934 guppy 1.9 Context;
935 guppy 1.7 /* if (u_pass_match(u, "-")) { */
936 guppy 1.8 noshare = 1; /* we *don't* want botnet passwords
937     * migrating */
938     set_user(&USERENTRY_PASS, u, par);
939     noshare = 0;
940 guppy 1.7 /* } */
941 segfault 1.1 }
942    
943     /* used to send a direct msg from Tcl on one bot to Tcl on another
944     * zapf <frombot> <tobot> <code [param]> */
945     static void bot_zapf(int idx, char *par)
946     {
947     char *from, *to;
948     int i;
949    
950 guppy 1.9 Context;
951 segfault 1.1 from = newsplit(&par);
952     to = newsplit(&par);
953     i = nextbot(from);
954     if (i != idx) {
955     fake_alert(idx, "direction", from);
956     return;
957     }
958     if (!strcasecmp(to, botnetnick)) {
959     /* for me! */
960     char *opcode;
961    
962     opcode = newsplit(&par);
963     check_tcl_bot(from, opcode, par);
964     return;
965     }
966     i = nextbot(to);
967     if (i >= 0)
968     botnet_send_zapf(i, from, to, par);
969     }
970    
971     /* used to send a global msg from Tcl on one bot to every other bot
972     * zapf-broad <frombot> <code [param]> */
973     static void bot_zapfbroad(int idx, char *par)
974     {
975     char *from, *opcode;
976     int i;
977    
978 guppy 1.9 Context;
979 segfault 1.1 from = newsplit(&par);
980     opcode = newsplit(&par);
981    
982     i = nextbot(from);
983     if (i != idx) {
984     fake_alert(idx, "direction", from);
985     return;
986     }
987     check_tcl_bot(from, opcode, par);
988     botnet_send_zapf_broad(idx, from, opcode, par);
989     }
990    
991     /* show motd to someone */
992     static void bot_motd(int idx, char *par)
993     {
994     FILE *vv;
995     char *s = TBUF, *who, *p;
996     int i;
997     struct flag_record fr =
998     {USER_BOT, 0, 0, 0, 0, 0};
999    
1000 guppy 1.9 Context;
1001 segfault 1.1
1002     who = newsplit(&par);
1003     if (!par[0] || !strcasecmp(par, botnetnick)) {
1004     int irc = 0;
1005    
1006     p = strchr(who, ':');
1007     if (p)
1008     p++;
1009     else
1010     p = who;
1011     if (who[0] == '!') {
1012     irc = HELP_IRC;
1013     fr.global |=USER_HIGHLITE;
1014    
1015     who++;
1016     } else if (who[0] == '#') {
1017     fr.global |=USER_HIGHLITE;
1018    
1019     who++;
1020     }
1021     putlog(LOG_CMDS, "*", "#%s# motd", p);
1022     vv = fopen(motdfile, "r");
1023     if (vv != NULL) {
1024     botnet_send_priv(idx, botnetnick, who, NULL, "--- %s\n", MISC_MOTDFILE);
1025     help_subst(NULL, NULL, 0, irc, NULL);
1026     while (!feof(vv)) {
1027     fgets(s, 120, vv);
1028     if (!feof(vv)) {
1029     if (s[strlen(s) - 1] == '\n')
1030     s[strlen(s) - 1] = 0;
1031     if (!s[0])
1032     strcpy(s, " ");
1033     help_subst(s, who, &fr, HELP_DCC, dcc[idx].nick);
1034     if (s[0])
1035     botnet_send_priv(idx, botnetnick, who, NULL, "%s", s);
1036     }
1037     }
1038     fclose(vv);
1039     } else
1040     botnet_send_priv(idx, botnetnick, who, NULL, "%s :(", MISC_NOMOTDFILE);
1041     } else {
1042     /* pass it on */
1043     i = nextbot(par);
1044     if (i >= 0)
1045     botnet_send_motd(i, who, par);
1046     }
1047     }
1048    
1049     /* these are still here, so that they will pass the relevant
1050     * requests through even if no filesys is loaded */
1051     /* filereject <bot:filepath> <sock:nick@bot> <reason...> */
1052     static void bot_filereject(int idx, char *par)
1053     {
1054     char *path, *to, *tobot, *p;
1055     int i;
1056    
1057 guppy 1.9 Context;
1058 segfault 1.1 path = newsplit(&par);
1059     to = newsplit(&par);
1060     if ((tobot = strchr(to, '@')))
1061     tobot++;
1062     else
1063     tobot = to; /* bot wants a file?! :) */
1064     if (strcasecmp(tobot, botnetnick)) { /* for me! */
1065     p = strchr(to, ':');
1066     if (p != NULL) {
1067     *p = 0;
1068     for (i = 0; i < dcc_total; i++) {
1069     if (dcc[i].sock == atoi(to))
1070     dprintf(i, "%s (%s): %s\n", BOT_XFERREJECTED, path, par);
1071     }
1072     *p = ':';
1073     }
1074     /* no ':'? malformed */
1075     putlog(LOG_FILES, "*", "%s %s: %s", path, MISC_REJECTED, par);
1076     } else { /* pass it on */
1077     i = nextbot(tobot);
1078     if (i >= 0)
1079     botnet_send_filereject(i, path, to, par);
1080     }
1081     }
1082    
1083     /* filereq <sock:nick@bot> <bot:file> */
1084     static void bot_filereq(int idx, char *tobot)
1085     {
1086     char *from, *path;
1087     int i;
1088    
1089 guppy 1.9 Context;
1090 segfault 1.1 from = newsplit(&tobot);
1091     if ((path = strchr(tobot, ':'))) {
1092     *path++ = 0;
1093    
1094     if (!strcasecmp(tobot, botnetnick)) { /* for me! */
1095     /* process this */
1096     module_entry *fs = module_find("filesys", 0, 0);
1097    
1098     if (fs == NULL)
1099     botnet_send_priv(idx, botnetnick, from, NULL, MOD_NOFILESYSMOD);
1100     else {
1101     Function f = fs->funcs[FILESYS_REMOTE_REQ];
1102    
1103     f(idx, from, path);
1104     }
1105     } else { /* pass it on */
1106     i = nextbot(tobot);
1107     if (i >= 0)
1108     botnet_send_filereq(i, from, tobot, path);
1109     }
1110     }
1111     }
1112    
1113     /* filesend <bot:path> <sock:nick@bot> <IP#> <port> <size> */
1114     static void bot_filesend(int idx, char *par)
1115     {
1116     char *botpath, *to, *tobot, *nick;
1117     int i;
1118     char *nfn;
1119    
1120 guppy 1.9 Context;
1121 segfault 1.1 botpath = newsplit(&par);
1122     to = newsplit(&par);
1123     if ((tobot = strchr(to, '@'))) {
1124     *tobot = 0;
1125     tobot++;
1126     } else {
1127     tobot = to;
1128     }
1129     if (!strcasecmp(tobot, botnetnick)) { /* for me! */
1130     nfn = strrchr(botpath, '/');
1131     if (nfn == NULL) {
1132     nfn = strrchr(botpath, ':');
1133     if (nfn == NULL)
1134     nfn = botpath; /* that's odd. */
1135     else
1136     nfn++;
1137     } else
1138     nfn++;
1139     if ((nick = strchr(to, ':')))
1140     nick++;
1141     else
1142     nick = to;
1143     /* send it to 'nick' as if it's from me */
1144     dprintf(DP_SERVER, "PRIVMSG %s :\001DCC SEND %s %s\001\n", nick, nfn, par);
1145     } else {
1146     i = nextbot(tobot);
1147     if (i >= 0) {
1148     *--tobot = '@';
1149     botnet_send_filesend(i, botpath, to, par);
1150     }
1151     }
1152     }
1153    
1154     static void bot_error(int idx, char *par)
1155     {
1156 guppy 1.9 Context;
1157 segfault 1.1 putlog(LOG_MISC | LOG_BOTS, "*", "%s: %s", dcc[idx].nick, par);
1158     }
1159    
1160     /* nc <bot> <sock> <newnick> */
1161     static void bot_nickchange(int idx, char *par)
1162     {
1163     char *bot, *ssock, *newnick;
1164     int sock, i;
1165    
1166 guppy 1.9 Context;
1167 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
1168     return;
1169     bot = newsplit(&par);
1170     #ifndef NO_OLD_BOTNET
1171     if (b_numver(idx) < NEAT_BOTNET) {
1172     fake_alert(idx, "botversion", "NEAT_BOTNET");
1173     return;
1174     }
1175     #endif
1176     i = nextbot(bot);
1177     if (i != idx) {
1178     fake_alert(idx, "direction", bot);
1179     return;
1180     }
1181     ssock = newsplit(&par);
1182     sock = base64_to_int(ssock);
1183     newnick = newsplit(&par);
1184     i = partynick(bot, sock, newnick);
1185     if (i < 0) {
1186     fake_alert(idx, "sock#", ssock);
1187     return;
1188     }
1189     chanout_but(-1, party[i].chan, "*** (%s) Nick change: %s -> %s\n",
1190     bot, newnick, party[i].nick);
1191     botnet_send_nkch_part(idx, i, newnick);
1192     }
1193    
1194     /* join <bot> <nick> <chan> <flag><sock> <from> */
1195     static void bot_join(int idx, char *par)
1196     {
1197     char *bot, *nick, *x, *y;
1198     struct userrec *u;
1199     int i, sock, chan, i2, linking = 0;
1200    
1201 guppy 1.9 Context;
1202 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
1203     return;
1204     bot = newsplit(&par);
1205     #ifndef NO_OLD_BOTNET
1206     if (b_numver(idx) >= NEAT_BOTNET)
1207     #endif
1208     if (bot[0] == '!') {
1209     linking = 1;
1210     bot++;
1211     }
1212     if (b_status(idx) & STAT_LINKING) {
1213     linking = 1;
1214     }
1215     nick = newsplit(&par);
1216     x = newsplit(&par);
1217     #ifndef NO_OLD_BOTNET
1218     if (b_numver(idx) < NEAT_BOTNET)
1219     chan = atoi(x);
1220     else
1221     #endif
1222     chan = base64_to_int(x);
1223     y = newsplit(&par);
1224     if ((chan < 0) || !y[0])
1225     return; /* woops! pre 1.2.1's send .chat off'ers
1226     * too!! */
1227     if (!y[0]) {
1228     y[0] = '-';
1229     sock = 0;
1230     } else {
1231     #ifndef NO_OLD_BOTNET
1232     if (b_numver(idx) < NEAT_BOTNET)
1233     sock = atoi(y + 1);
1234     else
1235     #endif
1236     sock = base64_to_int(y + 1);
1237     }
1238     /* 1.1 bots always send a sock#, even on a channel change
1239     * so if sock# is 0, this is from an old bot and we must tread softly
1240     * grab old sock# if there is one, otherwise make up one */
1241     if (sock == 0)
1242     sock = partysock(bot, nick);
1243     if (sock == 0)
1244     sock = fakesock++;
1245     i = nextbot(bot);
1246     if (i != idx) { /* ok, garbage from a 1.0g (who uses that
1247     * now?) OR raistlin being evil :) */
1248     fake_alert(idx, "direction", bot);
1249     return;
1250     }
1251     u = get_user_by_handle(userlist, nick);
1252     if (u) {
1253     sprintf(TBUF, "@%s", bot);
1254     touch_laston(u, TBUF, now);
1255     }
1256     i = addparty(bot, nick, chan, y[0], sock, par, &i2);
1257 guppy 1.9 Context;
1258 segfault 1.1 botnet_send_join_party(idx, linking, i2, i);
1259 guppy 1.9 Context;
1260 segfault 1.1 if (i != chan) {
1261     if (i >= 0) {
1262     if (b_numver(idx) >= NEAT_BOTNET)
1263     chanout_but(-1, i, "*** (%s) %s %s %s.\n", bot, nick, NET_LEFTTHE,
1264     i ? "channel" : "party line");
1265     check_tcl_chpt(bot, nick, sock, i);
1266     }
1267     if ((b_numver(idx) >= NEAT_BOTNET) && !linking)
1268     chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick, NET_JOINEDTHE,
1269     chan ? "channel" : "party line");
1270     check_tcl_chjn(bot, nick, chan, y[0], sock, par);
1271     }
1272 guppy 1.9 Context;
1273 segfault 1.1 }
1274    
1275     /* part <bot> <nick> <sock> [etc..] */
1276     static void bot_part(int idx, char *par)
1277     {
1278     char *bot, *nick, *etc;
1279     struct userrec *u;
1280     int sock, partyidx;
1281     int silent = 0;
1282    
1283 guppy 1.9 Context;
1284 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
1285     return;
1286     bot = newsplit(&par);
1287     if (bot[0] == '!') {
1288     silent = 1;
1289     bot++;
1290     }
1291     nick = newsplit(&par);
1292     etc = newsplit(&par);
1293     #ifndef NO_OLD_BOTNET
1294     if (b_numver(idx) < NEAT_BOTNET) {
1295     sock = atoi(etc);
1296     silent = 1;
1297     } else
1298     #endif
1299     sock = base64_to_int(etc);
1300     if (sock == 0)
1301     sock = partysock(bot, nick);
1302     u = get_user_by_handle(userlist, nick);
1303     if (u) {
1304     sprintf(TBUF, "@%s", bot);
1305     touch_laston(u, TBUF, now);
1306     }
1307     if ((partyidx = getparty(bot, sock)) != -1) {
1308 guppy 1.6 if (party[partyidx].chan >= 0)
1309     check_tcl_chpt(bot, nick, sock, party[partyidx].chan);
1310 segfault 1.1 if ((b_numver(idx) >= NEAT_BOTNET) && !silent) {
1311     register int chan = party[partyidx].chan;
1312    
1313     if (par[0])
1314     chanout_but(-1, chan, "*** (%s) %s %s %s (%s).\n", bot, nick,
1315     NET_LEFTTHE,
1316     chan ? "channel" : "party line", par);
1317     else
1318     chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick,
1319     NET_LEFTTHE,
1320     chan ? "channel" : "party line");
1321     }
1322     botnet_send_part_party(idx, partyidx, par, silent);
1323     remparty(bot, sock);
1324     }
1325 guppy 1.9 Context;
1326 segfault 1.1 }
1327    
1328     /* away <bot> <sock> <message> */
1329     /* null message = unaway */
1330     static void bot_away(int idx, char *par)
1331     {
1332     char *bot, *etc;
1333     int sock, partyidx, linking = 0;
1334    
1335 guppy 1.9 Context;
1336 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
1337     return;
1338     bot = newsplit(&par);
1339     #ifndef NO_OLD_BOTNET
1340     if (b_numver(idx) >= NEAT_BOTNET)
1341     #endif
1342     if (bot[0] == '!') {
1343     linking = 1;
1344     bot++;
1345     }
1346     if (b_status(idx) & STAT_LINKING) {
1347     linking = 1;
1348     }
1349     etc = newsplit(&par);
1350     #ifndef NO_OLD_BOTNET
1351     if (b_numver(idx) < NEAT_BOTNET)
1352     sock = atoi(etc);
1353     else
1354     #endif
1355     sock = base64_to_int(etc);
1356     if (sock == 0)
1357     sock = partysock(bot, etc);
1358     check_tcl_away(bot, sock, par);
1359     if (par[0]) {
1360     partystat(bot, sock, PLSTAT_AWAY, 0);
1361     partyaway(bot, sock, par);
1362     } else {
1363     partystat(bot, sock, 0, PLSTAT_AWAY);
1364     }
1365     partyidx = getparty(bot, sock);
1366     if ((b_numver(idx) >= NEAT_BOTNET) && !linking) {
1367     if (par[0])
1368     chanout_but(-1, party[partyidx].chan,
1369     "*** (%s) %s %s: %s.\n", bot,
1370     party[partyidx].nick, NET_AWAY, par);
1371     else
1372     chanout_but(-1, party[partyidx].chan,
1373     "*** (%s) %s %s.\n", bot,
1374     party[partyidx].nick, NET_UNAWAY);
1375     }
1376     botnet_send_away(idx, bot, sock, par, linking);
1377     }
1378    
1379     /* (a courtesy info to help during connect bursts) */
1380     /* idle <bot> <sock> <#secs> [away msg] */
1381     static void bot_idle(int idx, char *par)
1382     {
1383     char *bot, *work;
1384     int sock, idle;
1385    
1386 guppy 1.9 Context;
1387 segfault 1.1 if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
1388     return;
1389     bot = newsplit(&par);
1390     work = newsplit(&par);
1391     #ifndef NO_OLD_BOTNET
1392     if (b_numver(idx) < NEAT_BOTNET)
1393     sock = atoi(work);
1394     else
1395     #endif
1396     sock = base64_to_int(work);
1397     if (sock == 0)
1398     sock = partysock(bot, work);
1399     work = newsplit(&par);
1400     #ifndef NO_OLD_BOTNET
1401     if (b_numver(idx) < NEAT_BOTNET)
1402     idle = atoi(work);
1403     else
1404     #endif
1405     idle = base64_to_int(work);
1406     partysetidle(bot, sock, idle);
1407     if (par[0]) {
1408     partystat(bot, sock, PLSTAT_AWAY, 0);
1409     partyaway(bot, sock, par);
1410     }
1411     botnet_send_idle(idx, bot, sock, idle, par);
1412     }
1413    
1414     #ifndef NO_OLD_BOTNET
1415    
1416     static void bot_ufno(int idx, char *par)
1417     {
1418 guppy 1.9 Context;
1419 segfault 1.1 putlog(LOG_BOTS, "*", "%s %s: %s", USERF_REJECTED, dcc[idx].nick, par);
1420     dcc[idx].status &= ~STAT_OFFERED;
1421     if (!(dcc[idx].status & STAT_GETTING))
1422     dcc[idx].status &= ~STAT_SHARE;
1423     }
1424    
1425     static void bot_old_userfile(int idx, char *par)
1426     {
1427 guppy 1.9 Context;
1428 segfault 1.1 putlog(LOG_BOTS, "*", "%s %s", USERF_OLDSHARE, dcc[idx].nick);
1429     dprintf(idx, "uf-no %s\n", USERF_ANTIQUESHARE);
1430     }
1431    
1432     #endif
1433    
1434     void bot_share(int idx, char *par)
1435     {
1436 guppy 1.9 Context;
1437 segfault 1.1 sharein(idx, par);
1438     }
1439    
1440     /* v <frombot> <tobot> <idx:nick> */
1441     static void bot_versions(int sock, char *par)
1442     {
1443     char *frombot = newsplit(&par), *tobot, *from;
1444     module_entry *me;
1445    
1446     if (nextbot(frombot) != sock)
1447     fake_alert(sock, "versions-direction", frombot);
1448     else if (strcasecmp(tobot = newsplit(&par), botnetnick)) {
1449 guppy 1.11 if ((sock = nextbot(tobot)) >= 0)
1450 segfault 1.1 dprintf(sock, "v %s %s %s\n", frombot, tobot, par);
1451     } else {
1452     from = newsplit(&par);
1453     botnet_send_priv(sock, botnetnick, from, frombot, "Modules loaded:\n");
1454     for (me = module_list; me; me = me->next)
1455     botnet_send_priv(sock, botnetnick, from, frombot, " Module: %s (v%d.%d)\n",
1456     me->name, me->major, me->minor);
1457     botnet_send_priv(sock, botnetnick, from, frombot, "End of module list.\n");
1458     }
1459     }
1460    
1461     /* BOT COMMANDS */
1462     /* function call should be:
1463     * int bot_whatever(idx,"parameters");
1464 guppy 1.12 *
1465 segfault 1.1 * SORT these, dcc_bot uses a shortcut which requires them sorted
1466     *
1467     * yup, those are tokens there to allow a more efficient botnet as
1468     * time goes on (death to slowly upgrading llama's)
1469     */
1470     botcmd_t C_bot[] =
1471     {
1472     {"a", (Function) bot_actchan},
1473     #ifndef NO_OLD_BOTNET
1474     {"actchan", (Function) bot_actchan},
1475     #endif
1476     {"aw", (Function) bot_away},
1477     {"away", (Function) bot_away},
1478     {"bye", (Function) bot_bye},
1479     {"c", (Function) bot_chan2},
1480     #ifndef NO_OLD_BOTNET
1481     {"chan", (Function) bot_chan2},
1482     {"chat", (Function) bot_chat},
1483     #endif
1484     {"ct", (Function) bot_chat},
1485     {"e", (Function) bot_error},
1486     {"el", (Function) bot_endlink},
1487     #ifndef NO_OLD_BOTNET
1488     {"error", (Function) bot_error},
1489     #endif
1490     {"f!", (Function) bot_filereject},
1491     #ifndef NO_OLD_BOTNET
1492     {"filereject", (Function) bot_filereject},
1493     {"filereq", (Function) bot_filereq},
1494     {"filesend", (Function) bot_filesend},
1495     #endif
1496     {"fr", (Function) bot_filereq},
1497     {"fs", (Function) bot_filesend},
1498     {"h", (Function) bot_handshake},
1499     #ifndef NO_OLD_BOTNET
1500     {"handshake", (Function) bot_handshake},
1501     #endif
1502     {"i", (Function) bot_idle},
1503     {"i?", (Function) bot_infoq},
1504     #ifndef NO_OLD_BOTNET
1505     {"idle", (Function) bot_idle},
1506     {"info?", (Function) bot_infoq},
1507     #endif
1508     {"j", (Function) bot_join},
1509     #ifndef NO_OLD_BOTNET
1510     {"join", (Function) bot_join},
1511     #endif
1512     {"l", (Function) bot_link},
1513     #ifndef NO_OLD_BOTNET
1514     {"link", (Function) bot_link},
1515     {"linked", (Function) bot_linked},
1516     #endif
1517     {"m", (Function) bot_motd},
1518     #ifndef NO_OLD_BOTNET
1519     {"motd", (Function) bot_motd},
1520     #endif
1521     {"n", (Function) bot_nlinked},
1522     {"nc", (Function) bot_nickchange},
1523     #ifndef NO_OLD_BOTNET
1524     {"nlinked", (Function) bot_nlinked},
1525     #endif
1526     {"p", (Function) bot_priv},
1527     #ifndef NO_OLD_BOTNET
1528     {"part", (Function) bot_part},
1529     #endif
1530     {"pi", (Function) bot_ping},
1531     #ifndef NO_OLD_BOTNET
1532     {"ping", (Function) bot_ping},
1533     #endif
1534     {"po", (Function) bot_pong},
1535     #ifndef NO_OLD_BOTNET
1536     {"pong", (Function) bot_pong},
1537     {"priv", (Function) bot_priv},
1538     #endif
1539     {"pt", (Function) bot_part},
1540     {"r", (Function) bot_reject},
1541     #ifndef NO_OLD_BOTNET
1542     {"reject", (Function) bot_reject},
1543     #endif
1544     {"s", (Function) bot_share},
1545     {"t", (Function) bot_trace},
1546     {"tb", (Function) bot_thisbot},
1547     {"td", (Function) bot_traced},
1548     #ifndef NO_OLD_BOTNET
1549     {"thisbot", (Function) bot_thisbot},
1550     {"trace", (Function) bot_trace},
1551     {"traced", (Function) bot_traced},
1552     #endif
1553     {"u", (Function) bot_update},
1554     #ifndef NO_OLD_BOTNET
1555     {"uf-no", (Function) bot_ufno},
1556     #endif
1557     {"ul", (Function) bot_unlink},
1558     {"un", (Function) bot_unlinked},
1559     #ifndef NO_OLD_BOTNET
1560     {"unaway", (Function) bot_away},
1561     {"unlink", (Function) bot_unlink},
1562     {"unlinked", (Function) bot_unlinked},
1563     {"update", (Function) bot_update},
1564     {"userfile?", (Function) bot_old_userfile},
1565     #endif
1566     {"v", (Function) bot_versions},
1567     {"w", (Function) bot_who},
1568     #ifndef NO_OLD_BOTNET
1569     {"who", (Function) bot_who},
1570     #endif
1571     {"z", (Function) bot_zapf},
1572     #ifndef NO_OLD_BOTNET
1573     {"zapf", (Function) bot_zapf},
1574     {"zapf-broad", (Function) bot_zapfbroad},
1575     #endif
1576     {"zb", (Function) bot_zapfbroad},
1577     {0, 0}
1578     };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23