/[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.4 - (show annotations) (download) (as text)
Wed Sep 15 06:04:08 1999 UTC (21 years, 1 month ago) by poptix
Branch: MAIN
Changes since 1.3: +3 -3 lines
File MIME type: text/x-chdr

notesignore3 and notesignore4.patch

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23