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

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

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


Revision 1.1 - (show annotations) (download) (as text)
Mon Jul 26 21:11:06 2010 UTC (8 years, 11 months ago) by simple
Branch point for: eggheads, MAIN
File MIME type: text/x-chdr
Initial revision

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23