/[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.10 - (show annotations) (download) (as text)
Wed Nov 24 20:18:56 1999 UTC (20 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.9: +1 -1 lines
File MIME type: text/x-chdr
more patches

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23