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

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

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


Revision 1.15 - (show annotations) (download) (as text)
Sat Aug 19 00:49:04 2000 UTC (19 years ago) by guppy
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +2 -2 lines
File MIME type: text/x-chdr
Applied Sup's patch to remove a bell char form botmsg.c and I want to test cvslog <g>

1 /*
2 * botmsg.c -- handles:
3 * formatting of messages to be sent on the botnet
4 * sending differnet messages to different versioned bots
5 *
6 * by Darrin Smith (beldin@light.iinet.net.au)
7 *
8 * $Id: botmsg.c,v 1.14 2000/05/01 14:12:52 guppy Exp $
9 */
10 /*
11 * Copyright (C) 1997 Robey Pointer
12 * Copyright (C) 1999, 2000 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 */
28
29 #include "main.h"
30 #include "tandem.h"
31
32 extern struct dcc_t *dcc;
33 extern int dcc_total, tands;
34 extern char botnetnick[];
35 extern party_t *party;
36 extern Tcl_Interp *interp;
37 extern struct userrec *userlist;
38
39 static char OBUF[1024];
40
41 #ifndef NO_OLD_BOTNET
42 /* ditto for tandem bots */
43 void tandout_but EGG_VARARGS_DEF(int, arg1)
44 {
45 int i, x, l;
46 char *format;
47 char s[601];
48
49 va_list va;
50 x = EGG_VARARGS_START(int, arg1, va);
51 format = va_arg(va, char *);
52
53 #ifdef HAVE_VSNPRINTF
54 if ((l = vsnprintf(s, 511, format, va)) < 0)
55 s[l = 511] = 0;
56 #else
57 l = vsprintf(s, format, va);
58 #endif
59 va_end(va);
60 for (i = 0; i < dcc_total; i++)
61 if ((dcc[i].type == &DCC_BOT) && (i != x) &&
62 (b_numver(i) < NEAT_BOTNET))
63 tputs(dcc[i].sock, s, l);
64 }
65 #endif
66
67 /* thank you ircu :) */
68 static char tobase64array[64] =
69 {
70 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
71 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
72 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
73 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
74 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
75 '[', ']'
76 };
77
78 char *int_to_base64(unsigned int val)
79 {
80 static char buf_base64[12];
81 int i = 11;
82
83 buf_base64[11] = 0;
84 if (!val) {
85 buf_base64[10] = 'A';
86 return buf_base64 + 10;
87 }
88 while (val) {
89 i--;
90 buf_base64[i] = tobase64array[val & 0x3f];
91 val = val >> 6;
92 }
93 return buf_base64 + i;
94 }
95
96 char *int_to_base10(int val)
97 {
98 static char buf_base10[17];
99 int p = 0;
100 int i = 16;
101
102 buf_base10[16] = 0;
103 if (!val) {
104 buf_base10[15] = '0';
105 return buf_base10 + 15;
106 }
107 if (val < 0) {
108 p = 1;
109 val *= -1;
110 }
111 while (val) {
112 i--;
113 buf_base10[i] = '0' + (val % 10);
114 val /= 10;
115 }
116 if (p) {
117 i--;
118 buf_base10[i] = '-';
119 }
120 return buf_base10 + i;
121 }
122
123 char *unsigned_int_to_base10(unsigned int val)
124 {
125 static char buf_base10[16];
126 int i = 15;
127
128 buf_base10[15] = 0;
129 if (!val) {
130 buf_base10[14] = '0';
131 return buf_base10 + 14;
132 }
133 while (val) {
134 i--;
135 buf_base10[i] = '0' + (val % 10);
136 val /= 10;
137 }
138 return buf_base10 + i;
139 }
140
141 int simple_sprintf EGG_VARARGS_DEF(char *,arg1)
142 {
143 char *buf, *format, *s;
144 int c = 0, i;
145
146 va_list va;
147 buf = EGG_VARARGS_START(char *, arg1, va);
148 format = va_arg(va, char *);
149
150 while (*format && (c < 1023)) {
151 if (*format == '%') {
152 format++;
153 switch (*format) {
154 case 's':
155 s = va_arg(va, char *);
156
157 break;
158 case 'd':
159 case 'i':
160 i = va_arg(va, int);
161
162 s = int_to_base10(i);
163 break;
164 case 'D':
165 i = va_arg(va, int);
166
167 s = int_to_base64((unsigned int) i);
168 break;
169 case 'u':
170 i = va_arg(va, unsigned int);
171
172 s = unsigned_int_to_base10(i);
173 break;
174 case '%':
175 buf[c++] = *format++;
176 continue;
177 case 'c':
178 buf[c++] = (char) va_arg(va, int);
179
180 format++;
181 continue;
182 default:
183 continue;
184 }
185 if (s)
186 while (*s && (c < 1023))
187 buf[c++] = *s++;
188 format++;
189 } else
190 buf[c++] = *format++;
191 }
192 va_end(va);
193 buf[c] = 0;
194 return c;
195 }
196
197 /* ditto for tandem bots */
198 void send_tand_but(int x, char *buf, int len)
199 {
200 int i, iso = 0;
201
202 if (len < 0) {
203 len = -len;
204 iso = 1;
205 }
206 for (i = 0; i < dcc_total; i++)
207 if ((dcc[i].type == &DCC_BOT) && (i != x) &&
208 (b_numver(i) >= NEAT_BOTNET) &&
209 (!iso || !(bot_flags(dcc[i].user) & BOT_ISOLATE)))
210 tputs(dcc[i].sock, buf, len);
211 }
212
213 void botnet_send_bye()
214 {
215 if (tands > 0) {
216 send_tand_but(-1, "bye\n", 4);
217 #ifndef NO_OLD_BOTNET
218 tandout_but(-1, "bye\n");
219 #endif
220 }
221 }
222
223 void botnet_send_chan(int idx, char *botnick, char *user,
224 int chan, char *data)
225 {
226 int i;
227
228 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
229 if (user) {
230 i = simple_sprintf(OBUF, "c %s@%s %D %s\n", user, botnick, chan, data);
231 } else {
232 i = simple_sprintf(OBUF, "c %s %D %s\n", botnick, chan, data);
233 }
234 send_tand_but(idx, OBUF, -i);
235 #ifndef NO_OLD_BOTNET
236 tandout_but(idx, "chan %s%s%s %d %s\n", user ? user : "",
237 user ? "@" : "", botnick, chan, data);
238 #endif
239 }
240 }
241
242 void botnet_send_act(int idx, char *botnick, char *user,
243 int chan, char *data)
244 {
245 int i;
246
247 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
248 if (user) {
249 i = simple_sprintf(OBUF, "a %s@%s %D %s\n", user, botnick, chan, data);
250 } else {
251 i = simple_sprintf(OBUF, "a %s %D %s\n", botnick, chan, data);
252 }
253 send_tand_but(idx, OBUF, -i);
254 #ifndef NO_OLD_BOTNET
255 tandout_but(idx, "actchan %s%s%s %d %s\n", user ? user : "",
256 user ? "@" : "", botnick, chan, data);
257 #endif
258 }
259 }
260
261 void botnet_send_chat(int idx, char *botnick, char *data)
262 {
263 int i;
264
265 if (tands > 0) {
266 i = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
267 send_tand_but(idx, OBUF, -i);
268 #ifndef NO_OLD_BOTNET
269 tandout_but(idx, "chat %s %s\n", botnick, data);
270 #endif
271 }
272 }
273
274 void botnet_send_ping(int idx)
275 {
276 #ifndef NO_OLD_BOTNET
277 if (b_numver(idx) < NEAT_BOTNET)
278 tputs(dcc[idx].sock, "ping\n", 5);
279 else
280 #endif
281 tputs(dcc[idx].sock, "pi\n", 3);
282 }
283
284 void botnet_send_pong(int idx)
285 {
286 #ifndef NO_OLD_BOTNET
287 if (b_numver(idx) < NEAT_BOTNET)
288 tputs(dcc[idx].sock, "pong\n", 5);
289 else
290 #endif
291 tputs(dcc[idx].sock, "po\n", 3);
292 }
293
294 void botnet_send_priv EGG_VARARGS_DEF(int, arg1)
295 {
296 int idx, l;
297 char *from, *to, *tobot, *format;
298 char tbuf[1024];
299
300 va_list va;
301 idx = EGG_VARARGS_START(int, arg1, va);
302 from = va_arg(va, char *);
303 to = va_arg(va, char *);
304 tobot = va_arg(va, char *);
305 format = va_arg(va, char *);
306
307 #ifdef HAVE_VSNPRINTF
308 if (vsnprintf(tbuf, 450, format, va) < 0)
309 tbuf[450] = 0;
310 #else
311 vsprintf(tbuf, format, va);
312 #endif
313 va_end(va);
314 if (tobot) {
315 #ifndef NO_OLD_BOTNET
316 if (b_numver(idx) < NEAT_BOTNET)
317 l = simple_sprintf(OBUF, "priv %s %s@%s %s\n", from, to, tobot, tbuf);
318 else
319 #endif
320 l = simple_sprintf(OBUF, "p %s %s@%s %s\n", from, to, tobot, tbuf);
321 } else {
322 #ifndef NO_OLD_BOTNET
323 if (b_numver(idx) < NEAT_BOTNET)
324 l = simple_sprintf(OBUF, "priv %s %s %s\n", from, to, tbuf);
325 else
326 #endif
327 l = simple_sprintf(OBUF, "p %s %s %s\n", from, to, tbuf);
328 }
329 tputs(dcc[idx].sock, OBUF, l);
330 }
331
332 void botnet_send_who(int idx, char *from, char *to, int chan)
333 {
334 int l;
335
336 #ifndef NO_OLD_BOTNET
337 if (b_numver(idx) < NEAT_BOTNET)
338 l = simple_sprintf(OBUF, "who %s %s %d\n", from, to, chan);
339 else
340 #endif
341 l = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
342 tputs(dcc[idx].sock, OBUF, l);
343 }
344
345 void botnet_send_infoq(int idx, char *par)
346 {
347 int i = simple_sprintf(OBUF, "i? %s\n", par);
348
349 send_tand_but(idx, OBUF, i);
350 #ifndef NO_OLD_BOTNET
351 tandout_but(idx, "info? %s\n", par);
352 #endif
353 }
354
355 void botnet_send_unlink(int idx, char *who, char *via,
356 char *bot, char *reason)
357 {
358 int l;
359
360 #ifndef NO_OLD_BOTNET
361 if (b_numver(idx) < NEAT_BOTNET)
362 l = simple_sprintf(OBUF, "unlink %s %s %s %s\n", who, via, bot, reason);
363 else
364 #endif
365 l = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
366 tputs(dcc[idx].sock, OBUF, l);
367 }
368
369 void botnet_send_link(int idx, char *who, char *via, char *bot)
370 {
371 int l;
372
373 #ifndef NO_OLD_BOTNET
374 if (b_numver(idx) < NEAT_BOTNET)
375 l = simple_sprintf(OBUF, "link %s %s %s\n", who, via, bot);
376 else
377 #endif
378 l = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
379 tputs(dcc[idx].sock, OBUF, l);
380 }
381
382 void botnet_send_unlinked(int idx, char *bot, char *args)
383 {
384 int l;
385
386 Context;
387
388 if (tands > 0) {
389 l = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
390 send_tand_but(idx, OBUF, l);
391 #ifndef NO_OLD_BOTNET
392 if ((idx >= 0) && (b_numver(idx) >= NEAT_BOTNET) && args && args[0])
393 tandout_but(idx, "chat %s %s\n", lastbot(bot), args);
394 tandout_but(idx, "unlinked %s\n", bot);
395 #endif
396 }
397 }
398
399 void botnet_send_nlinked(int idx, char *bot, char *next, char flag,
400 int vernum)
401 {
402 int l;
403
404 if (tands > 0) {
405 l = simple_sprintf(OBUF, "n %s %s %c%D\n", bot, next, flag, vernum);
406 send_tand_but(idx, OBUF, l);
407 #ifndef NO_OLD_BOTNET
408 if (flag == '!') {
409 flag = '-';
410 tandout_but(idx, "chat %s %s %s\n", next, NET_LINKEDTO, bot);
411 }
412 tandout_but(idx, "nlinked %s %s %c%d\n", bot, next, flag, vernum);
413 #endif
414 }
415 }
416
417 void botnet_send_traced(int idx, char *bot, char *buf)
418 {
419 int l;
420
421 #ifndef NO_OLD_BOTNET
422 if (b_numver(idx) < NEAT_BOTNET)
423 l = simple_sprintf(OBUF, "traced %s %s\n", bot, buf);
424 else
425 #endif
426 l = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
427 tputs(dcc[idx].sock, OBUF, l);
428 }
429
430 void botnet_send_trace(int idx, char *to, char *from, char *buf)
431 {
432 int l;
433
434 #ifndef NO_OLD_BOTNET
435 if (b_numver(idx) < NEAT_BOTNET)
436 l = simple_sprintf(OBUF, "trace %s %s %s:%s\n", to, from, buf, botnetnick);
437 else
438 #endif
439 l = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, botnetnick);
440 tputs(dcc[idx].sock, OBUF, l);
441 }
442
443 void botnet_send_update(int idx, tand_t * ptr)
444 {
445 int l;
446
447 if (tands > 0) {
448 l = simple_sprintf(OBUF, "u %s %c%D\n", ptr->bot, ptr->share, ptr->ver);
449 send_tand_but(idx, OBUF, l);
450 #ifndef NO_OLD_BOTNET
451 tandout_but(idx, "update %s %c%d\n", ptr->bot, ptr->share, ptr->ver);
452 #endif
453 }
454 }
455
456 void botnet_send_reject(int idx, char *fromp, char *frombot, char *top,
457 char *tobot, char *reason)
458 {
459 int l;
460 char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
461
462 if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
463 if (tobot) {
464 simple_sprintf(to, "%s@%s", top, tobot);
465 top = to;
466 }
467 if (frombot) {
468 simple_sprintf(from, "%s@%s", fromp, frombot);
469 fromp = from;
470 }
471 if (!reason)
472 reason = "";
473 #ifndef NO_OLD_BOTNET
474 if (b_numver(idx) < NEAT_BOTNET)
475 l = simple_sprintf(OBUF, "reject %s %s %s\n", fromp, top, reason);
476 else
477 #endif
478 l = simple_sprintf(OBUF, "r %s %s %s\n", fromp, top, reason);
479 tputs(dcc[idx].sock, OBUF, l);
480 }
481 }
482
483 void botnet_send_zapf(int idx, char *a, char *b, char *c)
484 {
485 int l;
486
487 #ifndef NO_OLD_BOTNET
488 if (b_numver(idx) < NEAT_BOTNET)
489 l = simple_sprintf(OBUF, "zapf %s %s %s\n", a, b, c);
490 else
491 #endif
492 l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
493 tputs(dcc[idx].sock, OBUF, l);
494 }
495
496 void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
497 {
498 int l;
499
500 if (tands > 0) {
501 l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
502 send_tand_but(idx, OBUF, l);
503 #ifndef NO_OLD_BOTNET
504 tandout_but(idx, "zapf-broad %s\n", OBUF + 3);
505 #endif
506 }
507 }
508
509 void botnet_send_motd(int idx, char *from, char *to)
510 {
511 int l;
512
513 #ifndef NO_OLD_BOTNET
514 if (b_numver(idx) < NEAT_BOTNET)
515 l = simple_sprintf(OBUF, "motd %s %s\n", from, to);
516 else
517 #endif
518 l = simple_sprintf(OBUF, "m %s %s\n", from, to);
519 tputs(dcc[idx].sock, OBUF, l);
520 }
521
522 void botnet_send_filereject(int idx, char *path, char *from, char *reason)
523 {
524 int l;
525
526 #ifndef NO_OLD_BOTNET
527 if (b_numver(idx) < NEAT_BOTNET)
528 l = simple_sprintf(OBUF, "filereject %s %s %s\n", path, from, reason);
529 else
530 #endif
531 l = simple_sprintf(OBUF, "f! %s %s %s\n", path, from, reason);
532 tputs(dcc[idx].sock, OBUF, l);
533 }
534
535 void botnet_send_filesend(int idx, char *path, char *from, char *data)
536 {
537 int l;
538
539 #ifndef NO_OLD_BOTNET
540 if (b_numver(idx) < NEAT_BOTNET)
541 l = simple_sprintf(OBUF, "filesend %s %s %s\n", path, from, data);
542 else
543 #endif
544 l = simple_sprintf(OBUF, "fs %s %s %s\n", path, from, data);
545 tputs(dcc[idx].sock, OBUF, l);
546 }
547
548 void botnet_send_filereq(int idx, char *from, char *bot, char *path)
549 {
550 int l;
551
552 #ifndef NO_OLD_BOTNET
553 if (b_numver(idx) < NEAT_BOTNET)
554 l = simple_sprintf(OBUF, "filereq %s %s:%s\n", from, bot, path);
555 else
556 #endif
557 l = simple_sprintf(OBUF, "fr %s %s:%s\n", from, bot, path);
558 tputs(dcc[idx].sock, OBUF, l);
559 }
560
561 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
562 {
563 int l;
564
565 Context;
566 if (tands > 0) {
567 l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle,
568 away ? away : "");
569 send_tand_but(idx, OBUF, -l);
570 #ifndef NO_OLD_BOTNET
571 if (away && away[0])
572 tandout_but(idx, "away %s %d %s\n", bot, sock, away);
573 tandout_but(idx, "idle %s %d %d\n", bot, sock, idle);
574 #endif
575 }
576 }
577
578 void botnet_send_away(int idx, char *bot, int sock,
579 char *msg, int linking)
580 {
581 int l;
582
583 if (tands > 0) {
584 l = simple_sprintf(OBUF, "aw %s%s %D %s\n",
585 ((idx >= 0) && linking) ? "!" : "",
586 bot, sock, msg ? msg : "");
587 send_tand_but(idx, OBUF, -l);
588 #ifndef NO_OLD_BOTNET
589 if (msg) {
590 if (idx < 0) {
591 tandout_but(idx, "chan %s %d %s is now away: %s.\n", bot,
592 dcc[linking].u.chat->channel, dcc[linking].nick,
593 msg);
594 } else if ((b_numver(idx) >= NEAT_BOTNET)) {
595 int partyidx = getparty(bot, sock);
596
597 if (partyidx >= 0)
598 tandout_but(idx, "chan %s %d %s %s: %s.\n", bot,
599 party[partyidx].chan, party[partyidx].nick,
600 NET_AWAY, msg);
601 }
602 tandout_but(idx, "away %s %d %s\n", bot, sock, msg);
603 } else {
604 if (idx < 0) {
605 tandout_but(idx, "chan %s %d %s %s.\n", bot,
606 dcc[linking].u.chat->channel, dcc[linking].nick,
607 NET_UNAWAY);
608 } else if (b_numver(idx) >= NEAT_BOTNET) {
609 int partyidx = getparty(bot, sock);
610
611 if (partyidx >= 0)
612 tandout_but(idx, "chan %s %d %s %s.\n", bot,
613 party[partyidx].chan, party[partyidx].nick,
614 NET_UNAWAY);
615 }
616 tandout_but(idx, "unaway %s %d\n", bot, sock);
617 }
618 #endif
619 }
620 }
621
622 void botnet_send_join_idx(int useridx, int oldchan)
623 {
624 int l;
625
626 if (tands > 0) {
627 l = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
628 botnetnick, dcc[useridx].nick,
629 dcc[useridx].u.chat->channel, geticon(useridx),
630 dcc[useridx].sock, dcc[useridx].host);
631 send_tand_but(-1, OBUF, -l);
632 #ifndef NO_OLD_BOTNET
633 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
634 dcc[useridx].nick, dcc[useridx].u.chat->channel,
635 geticon(useridx), dcc[useridx].sock, dcc[useridx].host);
636 tandout_but(-1, "chan %s %d %s %s %s.\n",
637 botnetnick, dcc[useridx].u.chat->channel,
638 dcc[useridx].nick, NET_JOINEDTHE,
639 dcc[useridx].u.chat->channel ? "channel" : "party line");
640 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS)) {
641 tandout_but(-1, "chan %s %d %s %s %s.\n",
642 botnetnick, oldchan,
643 dcc[useridx].nick, NET_LEFTTHE,
644 oldchan ? "channel" : "party line");
645 }
646 #endif
647 }
648 }
649
650 void botnet_send_join_party(int idx, int linking, int useridx, int oldchan)
651 {
652 int l;
653
654 Context;
655 if (tands > 0) {
656 l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
657 party[useridx].bot, party[useridx].nick,
658 party[useridx].chan, party[useridx].flag,
659 party[useridx].sock,
660 safe_str(party[useridx].from));
661 send_tand_but(idx, OBUF, -l);
662 #ifndef NO_OLD_BOTNET
663 tandout_but(idx, "join %s %s %d %c%d %s\n", party[useridx].bot,
664 party[useridx].nick, party[useridx].chan,
665 party[useridx].flag, party[useridx].sock,
666 safe_str(party[useridx].from));
667 if ((idx < 0) || (!linking && (b_numver(idx) >= NEAT_BOTNET))) {
668 tandout_but(idx, "chan %s %d %s %s %s.\n",
669 party[useridx].bot, party[useridx].chan,
670 party[useridx].nick, NET_JOINEDTHE,
671 party[useridx].chan ? "channel" : "party line");
672 }
673 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS) &&
674 ((idx < 0) || (b_numver(idx) >= NEAT_BOTNET))) {
675 tandout_but(idx, "chan %s %d %s %s %s.\n",
676 party[useridx].bot, oldchan, party[useridx].nick,
677 NET_LEFTTHE,
678 party[useridx].chan ? "channel" : "party line");
679 }
680 #endif
681 }
682 }
683
684 void botnet_send_part_idx(int useridx, char *reason)
685 {
686 int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", botnetnick,
687 dcc[useridx].nick, dcc[useridx].sock,
688 reason ? reason : "");
689
690 if (tands > 0) {
691 send_tand_but(-1, OBUF, -l);
692 #ifndef NO_OLD_BOTNET
693 tandout_but(-1, "part %s %s %d\n", botnetnick,
694 dcc[useridx].nick, dcc[useridx].sock);
695 tandout_but(-1, "chan %s %d %s has left the %s%s%s.\n",
696 botnetnick, dcc[useridx].u.chat->channel,
697 dcc[useridx].nick,
698 dcc[useridx].u.chat->channel ? "channel" : "party line",
699 reason ? ": " : "", reason ? reason : "");
700 #endif
701 }
702 }
703
704 void botnet_send_part_party(int idx, int partyidx, char *reason,
705 int silent)
706 {
707 int l;
708
709 if (tands > 0) {
710 l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
711 silent ? "!" : "", party[partyidx].bot,
712 party[partyidx].nick, party[partyidx].sock,
713 reason ? reason : "");
714 send_tand_but(idx, OBUF, -l);
715 #ifndef NO_OLD_BOTNET
716 tandout_but(idx, "part %s %s %d\n", party[partyidx].bot,
717 party[partyidx].nick, party[partyidx].sock);
718 if (((idx < 0) || (b_numver(idx) >= NEAT_BOTNET)) && !silent) {
719 tandout_but(idx, "chan %s %d %s has left the %s%s%s.\n",
720 party[partyidx].bot, party[partyidx].chan,
721 party[partyidx].nick,
722 party[partyidx].chan ? "channel" : "party line",
723 reason ? ": " : "", reason ? reason : "");
724 }
725 #endif
726 }
727 }
728
729 void botnet_send_nkch(int useridx, char *oldnick)
730 {
731 int l;
732
733 if (tands > 0) {
734 l = simple_sprintf(OBUF, "nc %s %D %s\n", botnetnick,
735 dcc[useridx].sock, dcc[useridx].nick);
736 send_tand_but(-1, OBUF, -l);
737 #ifndef NO_OLD_BOTNET
738 tandout_but(-1, "part %s %s %d\n", botnetnick,
739 dcc[useridx].nick, dcc[useridx].sock);
740 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
741 dcc[useridx].nick, dcc[useridx].u.chat->channel,
742 geticon(useridx), dcc[useridx].sock, dcc[useridx].host);
743 tandout_but(-1, "chan %s %d %s: %s -> %s.\n",
744 botnetnick, dcc[useridx].u.chat->channel,
745 oldnick, NET_NICKCHANGE, dcc[useridx].nick);
746 #endif
747 }
748 }
749
750 void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
751 {
752 int l;
753
754 if (tands > 0) {
755 l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
756 party[useridx].sock, party[useridx].nick);
757 send_tand_but(butidx, OBUF, -l);
758 #ifndef NO_OLD_BOTNET
759 tandout_but(butidx, "part %s %s %d\n", party[useridx].bot,
760 party[useridx].nick, party[useridx].sock);
761 tandout_but(butidx, "join %s %s %d %c%d %s\n", party[useridx].bot,
762 party[useridx].nick, party[useridx].chan,
763 party[useridx].flag, party[useridx].sock,
764 safe_str(party[useridx].from));
765 tandout_but(butidx, "chan %s %d %s : %s -> %s.\n",
766 party[useridx].bot, party[useridx].chan,
767 NET_NICKCHANGE,
768 oldnick, party[useridx].nick);
769 #endif
770 }
771 }
772
773 /* this part of add_note is more relevant to the botnet than
774 * to the notes file */
775 int add_note(char *to, char *from, char *msg, int idx, int echo)
776 {
777 int status, i, iaway, sock;
778 char *p, botf[81], ss[81], ssf[81];
779 struct userrec *u;
780
781 if (strlen(msg) > 450)
782 msg[450] = 0; /* notes have a limit */
783 /* note length + PRIVMSG header + nickname + date must be <512 */
784 p = strchr(to, '@');
785 if (p != NULL) { /* cross-bot note */
786 char x[21];
787
788 *p = 0;
789 strncpy(x, to, 20);
790 x[20] = 0;
791 *p = '@';
792 p++;
793 if (!strcasecmp(p, botnetnick)) /* to me?? */
794 return add_note(x, from, msg, idx, echo); /* start over, dimwit. */
795 if (strcasecmp(from, botnetnick)) {
796 if (strlen(from) > 40)
797 from[40] = 0;
798 if (strchr(from, '@')) {
799 strcpy(botf, from);
800 } else
801 sprintf(botf, "%s@%s", from, botnetnick);
802 } else
803 strcpy(botf, botnetnick);
804 i = nextbot(p);
805 if (i < 0) {
806 if (idx >= 0)
807 dprintf(idx, BOT_NOTHERE);
808 return NOTE_ERROR;
809 }
810 if ((idx >= 0) && (echo))
811 dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
812 if (idx >= 0) {
813 sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
814 botnet_send_priv(i, ssf, x, p, "%s", msg);
815 } else
816 botnet_send_priv(i, botf, x, p, "%s", msg);
817 return NOTE_OK; /* forwarded to the right bot */
818 }
819 /* might be form "sock:nick" */
820 splitc(ssf, from, ':');
821 rmspace(ssf);
822 splitc(ss, to, ':');
823 rmspace(ss);
824 if (!ss[0])
825 sock = (-1);
826 else
827 sock = atoi(ss);
828 /* don't process if there's a note binding for it */
829 if (idx != (-2)) { /* notes from bots don't trigger it */
830 if (check_tcl_note(from, to, msg)) {
831 if ((idx >= 0) && (echo))
832 dprintf(idx, "-> %s: %s\n", to, msg);
833 return NOTE_TCL;
834 }
835 }
836 if (!(u = get_user_by_handle(userlist, to))) {
837 if (idx >= 0)
838 dprintf(idx, USERF_UNKNOWN);
839 return NOTE_ERROR;
840 }
841 if (is_bot(u)) {
842 if (idx >= 0)
843 dprintf(idx, BOT_NONOTES);
844 return NOTE_ERROR;
845 }
846 if (match_noterej(u, from)) {
847 if (idx >= 0)
848 dprintf(idx, "%s %s\n", u->handle, "rejected your note.");
849 return NOTE_REJECT;
850 }
851 status = NOTE_STORED;
852 iaway = 0;
853 /* online right now? */
854 for (i = 0; i < dcc_total; i++) {
855 if ((dcc[i].type->flags & DCT_GETNOTES) &&
856 ((sock == (-1)) || (sock == dcc[i].sock)) &&
857 (!strcasecmp(dcc[i].nick, to))) {
858 int aok = 1;
859
860 if (dcc[i].type == &DCC_CHAT)
861 if ((dcc[i].u.chat->away != NULL) &&
862 (idx != (-2))) {
863 /* only check away if it's not from a bot */
864 aok = 0;
865 if (idx >= 0)
866 dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
867 dcc[i].u.chat->away);
868 if (!iaway)
869 iaway = i;
870 status = NOTE_AWAY;
871 }
872 if (aok) {
873 char *p, *fr = from;
874 int l = 0;
875 char work[1024];
876
877 while ((*msg == '<') || (*msg == '>')) {
878 p = newsplit(&msg);
879 if (*p == '<')
880 l += simple_sprintf(work + l, "via %s, ", p + 1);
881 else if (*from == '@')
882 fr = p + 1;
883 }
884 if ((idx == (-2)) || (!strcasecmp(from, botnetnick)))
885 dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
886 else
887 dprintf(i, "Note [%s]: %s%s\n", fr, l ? work : "", msg);
888 if ((idx >= 0) && (echo))
889 dprintf(idx, "-> %s: %s\n", to, msg);
890 return NOTE_OK;
891 }
892 }
893 }
894 if (idx == (-2))
895 return NOTE_OK; /* error msg from a tandembot: don't store */
896 /* call store note here */
897 Tcl_SetVar(interp, "_from", from, 0);
898 Tcl_SetVar(interp, "_to", to, 0);
899 Tcl_SetVar(interp, "_data", msg, 0);
900 simple_sprintf(ss, "%d", dcc[idx].sock);
901 Tcl_SetVar(interp, "_idx", ss, 0);
902 if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) == TCL_OK) {
903 if (interp->result && interp->result[0]) {
904 /* strncpy(to, interp->result, NOTENAMELEN);
905 to[NOTENAMELEN] = 0; */ /* notebug fixed ;) -- drummer 29May1999 */
906 status = NOTE_FWD;
907 }
908 if (status == NOTE_AWAY) {
909 /* user is away in all sessions -- just notify the user that a
910 * message arrived and was stored. (only oldest session is notified.) */
911 dprintf(iaway, "*** %s.\n", BOT_NOTEARRIVED);
912 }
913 return status;
914 }
915 return NOTE_ERROR;
916 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23