/[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.1.1.2.1 - (show annotations) (download) (as text) (vendor branch)
Wed Nov 10 13:39:19 2010 UTC (8 years, 9 months ago) by pseudo
Branch: gettext
Changes since 1.1.1.1: +25 -26 lines
File MIME type: text/x-chdr
Converted remaining lang #defines in the core to english strings from core.english.lang. Gettextified most of the hardcoded strings.

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.1.1.1 2010/07/26 21:11:06 simple 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, _("Linked to"), 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 _("is now 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 _("is no longer away"));
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, _("is no longer away"));
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, _("has joined the"),
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.\n", botnetnick, oldchan,
629 dcc[useridx].nick, oldchan ? _("has left the channel)") :
630 _("has left the 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 if (tands > 0) {
641 l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
642 party[useridx].bot, party[useridx].nick,
643 party[useridx].chan, party[useridx].flag,
644 party[useridx].sock,
645 party[useridx].from ? party[useridx].from : "");
646 send_tand_but(idx, OBUF, -l);
647 #ifndef NO_OLD_BOTNET
648 tandout_but(idx, "join %s %s %d %c%d %s\n", party[useridx].bot,
649 party[useridx].nick, party[useridx].chan,
650 party[useridx].flag, party[useridx].sock,
651 party[useridx].from ? party[useridx].from : "");
652 if ((idx < 0) || (!linking && (b_numver(idx) >= NEAT_BOTNET))) {
653 tandout_but(idx, "chan %s %d %s %s.\n", party[useridx].bot,
654 party[useridx].chan, party[useridx].nick,
655 party[useridx].chan ? _("has joined the channel") :
656 _("has joined the party line"));
657 }
658 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS) &&
659 ((idx < 0) || (b_numver(idx) >= NEAT_BOTNET))) {
660 tandout_but(idx, "chan %s %d %s %s.\n", party[useridx].bot, oldchan,
661 party[useridx].nick, party[useridx].chan ?
662 _("has left the channel") : _("has left the party line"));
663 }
664 #endif
665 }
666 }
667
668 void botnet_send_part_idx(int useridx, char *reason)
669 {
670 int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", botnetnick,
671 dcc[useridx].nick, dcc[useridx].sock,
672 reason ? reason : "");
673
674 if (tands > 0) {
675 send_tand_but(-1, OBUF, -l);
676 #ifndef NO_OLD_BOTNET
677 tandout_but(-1, "part %s %s %d\n", botnetnick,
678 dcc[useridx].nick, dcc[useridx].sock);
679 tandout_but(-1, "chan %s %d %s has left the %s%s%s.\n",
680 botnetnick, dcc[useridx].u.chat->channel,
681 dcc[useridx].nick,
682 dcc[useridx].u.chat->channel ? "channel" : "party line",
683 reason ? ": " : "", reason ? reason : "");
684 #endif
685 }
686 }
687
688 void botnet_send_part_party(int idx, int partyidx, char *reason, int silent)
689 {
690 int l;
691
692 if (tands > 0) {
693 l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
694 silent ? "!" : "", party[partyidx].bot,
695 party[partyidx].nick, party[partyidx].sock,
696 reason ? reason : "");
697 send_tand_but(idx, OBUF, -l);
698 #ifndef NO_OLD_BOTNET
699 tandout_but(idx, "part %s %s %d\n", party[partyidx].bot,
700 party[partyidx].nick, party[partyidx].sock);
701 if (((idx < 0) || (b_numver(idx) >= NEAT_BOTNET)) && !silent) {
702 tandout_but(idx, "chan %s %d %s has left the %s%s%s.\n",
703 party[partyidx].bot, party[partyidx].chan,
704 party[partyidx].nick,
705 party[partyidx].chan ? "channel" : "party line",
706 reason ? ": " : "", reason ? reason : "");
707 }
708 #endif
709 }
710 }
711
712 void botnet_send_nkch(int useridx, char *oldnick)
713 {
714 int l;
715
716 if (tands > 0) {
717 l = simple_sprintf(OBUF, "nc %s %D %s\n", botnetnick,
718 dcc[useridx].sock, dcc[useridx].nick);
719 send_tand_but(-1, OBUF, -l);
720 #ifndef NO_OLD_BOTNET
721 tandout_but(-1, "part %s %s %d\n", botnetnick,
722 dcc[useridx].nick, dcc[useridx].sock);
723 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
724 dcc[useridx].nick, dcc[useridx].u.chat->channel,
725 geticon(useridx), dcc[useridx].sock, dcc[useridx].host);
726 tandout_but(-1, "chan %s %d %s: %s -> %s.\n",
727 botnetnick, dcc[useridx].u.chat->channel,
728 oldnick, _("Nick Change:"), dcc[useridx].nick);
729 #endif
730 }
731 }
732
733 void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
734 {
735 int l;
736
737 if (tands > 0) {
738 l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
739 party[useridx].sock, party[useridx].nick);
740 send_tand_but(butidx, OBUF, -l);
741 #ifndef NO_OLD_BOTNET
742 tandout_but(butidx, "part %s %s %d\n", party[useridx].bot,
743 party[useridx].nick, party[useridx].sock);
744 tandout_but(butidx, "join %s %s %d %c%d %s\n", party[useridx].bot,
745 party[useridx].nick, party[useridx].chan,
746 party[useridx].flag, party[useridx].sock,
747 party[useridx].from ? party[useridx].from : "");
748 tandout_but(butidx, "chan %s %d %s : %s -> %s.\n",
749 party[useridx].bot, party[useridx].chan,
750 _("Nick Change:"), oldnick, party[useridx].nick);
751 #endif
752 }
753 }
754
755 /* This part of add_note is more relevant to the botnet than
756 * to the notes file.
757 */
758 int add_note(char *to, char *from, char *msg, int idx, int echo)
759 {
760 int status, i, iaway, sock;
761 char *p, botf[81], ss[81], ssf[81];
762 struct userrec *u;
763
764 /* Notes have a length limit. Note + PRIVMSG header + nick + date must
765 * be less than 512.
766 */
767 if (strlen(msg) > 450)
768 msg[450] = 0;
769
770 /* Is this a cross-bot note? If it is, 'to' will be of the format
771 * 'user@bot'.
772 */
773 p = strchr(to, '@');
774 if (p != NULL) {
775 char x[21];
776
777 *p = 0;
778 strncpy(x, to, 20);
779 x[20] = 0;
780 *p = '@';
781 p++;
782
783 if (!egg_strcasecmp(p, botnetnick)) /* To me?? */
784 return add_note(x, from, msg, idx, echo); /* Start over, dimwit. */
785
786 if (egg_strcasecmp(from, botnetnick)) {
787 if (strlen(from) > 40)
788 from[40] = 0;
789
790 if (strchr(from, '@')) {
791 strcpy(botf, from);
792 } else
793 sprintf(botf, "%s@%s", from, botnetnick);
794
795 } else
796 strcpy(botf, botnetnick);
797
798 i = nextbot(p);
799 if (i < 0) {
800 if (idx >= 0)
801 dprintf(idx, _("That bot isn't here.\n"));
802
803 return NOTE_ERROR;
804 }
805
806 if (idx >= 0 && echo)
807 dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
808
809 if (idx >= 0) {
810 sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
811 botnet_send_priv(i, ssf, x, p, "%s", msg);
812 } else
813 botnet_send_priv(i, botf, x, p, "%s", msg);
814
815 return NOTE_OK; /* Forwarded to the right bot */
816 }
817
818 /* Might be form "sock:nick" */
819 splitc(ssf, from, ':');
820 rmspace(ssf);
821 splitc(ss, to, ':');
822 rmspace(ss);
823 if (!ss[0])
824 sock = -1;
825 else
826 sock = atoi(ss);
827
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
834 return NOTE_TCL;
835 }
836 }
837
838 /* Valid user? */
839 u = get_user_by_handle(userlist, to);
840 if (!u) {
841 if (idx >= 0)
842 dprintf(idx, _("I don't know anyone by that name.\n"));
843
844 return NOTE_ERROR;
845 }
846
847 /* Is the note to a bot? */
848 if (is_bot(u)) {
849 if (idx >= 0)
850 dprintf(idx, _("That's a bot. You can't leave notes for a bot.\n"));
851
852 return NOTE_ERROR;
853 }
854
855 /* Is user rejecting notes from this source? */
856 if (match_noterej(u, from)) {
857 if (idx >= 0)
858 dprintf(idx, _("%s rejected your note.\n"), u->handle);
859
860 return NOTE_REJECT;
861 }
862
863 status = NOTE_STORED;
864 iaway = 0;
865
866 /* Online right now? */
867 for (i = 0; i < dcc_total; i++) {
868 if ((dcc[i].type->flags & DCT_GETNOTES) &&
869 (sock == -1 || sock == dcc[i].sock) &&
870 !egg_strcasecmp(dcc[i].nick, to)) {
871 int aok = 1;
872
873 if (dcc[i].type == &DCC_CHAT) {
874
875 /* Only check away if it's not from a bot. */
876 if (dcc[i].u.chat->away != NULL && idx != -2) {
877 aok = 0;
878
879 if (idx >= 0)
880 dprintf(idx, _("%s is away: %s\n"), dcc[i].nick,
881 dcc[i].u.chat->away);
882
883 if (!iaway)
884 iaway = i;
885 status = NOTE_AWAY;
886 }
887 }
888
889 if (aok) {
890 char *p, *fr = from, work[1024];
891 int l = 0;
892
893 while (*msg == '<' || *msg == '>') {
894 p = newsplit(&msg);
895
896 if (*p == '<')
897 l += simple_sprintf(work + l, "via %s, ", p + 1);
898 else if (*from == '@')
899 fr = p + 1;
900 }
901
902 if (idx == -2 || !egg_strcasecmp(from, botnetnick))
903 dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
904 else
905 dprintf(i, _("%cNote [%s]: %s%s\n"), 7, fr, l ? work : "", msg);
906
907 if (idx >= 0 && echo)
908 dprintf(idx, "-> %s: %s\n", to, msg);
909
910 return NOTE_OK;
911 }
912 }
913 }
914
915 if (idx == -2)
916 return NOTE_OK; /* Error msg from a tandembot: don't store. */
917
918 /* Call 'storenote' Tcl command. */
919 simple_sprintf(ss, "%d", (idx >= 0) ? dcc[idx].sock : -1);
920 Tcl_SetVar(interp, "_from", from, 0);
921 Tcl_SetVar(interp, "_to", to, 0);
922 Tcl_SetVar(interp, "_data", msg, 0);
923 Tcl_SetVar(interp, "_idx", ss, 0);
924 if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) ==
925 TCL_OK) {
926
927 if (!tcl_resultempty())
928 status = NOTE_FWD;
929
930 /* User is away in all sessions -- just notify the user that a
931 * message arrived and was stored (only oldest session is notified).
932 */
933 if (status == NOTE_AWAY)
934 dprintf(iaway, _("*** Note arrived for you.\n"));
935
936 return status;
937 }
938
939 /* If we haven't returned anything else by now, assume an error occurred. */
940 return NOTE_ERROR;
941 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23