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

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

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


Revision 1.39 - (show annotations) (download) (as text)
Sun Sep 22 01:25:19 2002 UTC (16 years, 9 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.38: +1 -1 lines
File MIME type: text/x-chdr
FILE REMOVED
* Remove unnecessary files (botnet stuff)

1 /*
2 * botmsg.c --
3 *
4 * formatting of messages to be sent on the botnet
5 * sending differnet messages to different versioned bots
6 *
7 * by Darrin Smith (beldin@light.iinet.net.au)
8 */
9 /*
10 * Copyright (C) 1997 Robey Pointer
11 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
28 #ifndef lint
29 static const char rcsid[] = "$Id: botmsg.c,v 1.38 2002/05/28 20:36:07 stdarg Exp $";
30 #endif
31
32 #include "main.h"
33 #include "tandem.h"
34 #include "misc.h"
35 #include "modules.h" /* match_noterej, storenote */
36 #include "cmdt.h" /* cmd_t */
37 #include "core_binds.h" /* check_bind_note */
38 #include "users.h" /* bot_flags, get_user_by_handle, is_bot */
39 #include "botnet.h" /* lastbot, getparty, nextbot */
40 #include "botcmd.h" /* add_note */
41 #include "net.h" /* tputs */
42 #include "dccutil.h" /* dprintf_eggdrop */
43 #include "botmsg.h" /* prototypes */
44
45 extern struct dcc_t *dcc;
46 extern int dcc_total, tands;
47 extern char botnetnick[];
48 extern party_t *party;
49 extern struct userrec *userlist;
50
51 static char OBUF[1024];
52
53 #ifndef MAKING_MODS
54 extern struct dcc_table DCC_BOT, DCC_CHAT;
55 #endif /* MAKING_MODS */
56
57
58 #ifndef NO_OLD_BOTNET
59 /* Ditto for tandem bots
60 */
61 void tandout_but EGG_VARARGS_DEF(int, arg1)
62 {
63 int i, x, len;
64 char *format;
65 char s[601];
66 va_list va;
67
68 x = EGG_VARARGS_START(int, arg1, va);
69 format = va_arg(va, char *);
70 len = vsnprintf(s, 511, format, va);
71 va_end(va);
72 if (len < 0 || len >= sizeof(s)) len = sizeof(s)-1;
73 s[len] = 0;
74
75 for (i = 0; i < dcc_total; i++)
76 if ((dcc[i].type == &DCC_BOT) && (i != x) &&
77 (b_numver(i) < NEAT_BOTNET))
78 tputs(dcc[i].sock, s, len);
79 }
80 #endif
81
82 /* Ditto for tandem bots
83 */
84 void send_tand_but(int x, char *buf, int len)
85 {
86 int i, iso = 0;
87
88 if (len < 0) {
89 len = -len;
90 iso = 1;
91 }
92 for (i = 0; i < dcc_total; i++)
93 if ((dcc[i].type == &DCC_BOT) && (i != x) &&
94 (b_numver(i) >= NEAT_BOTNET) &&
95 (!iso || !(bot_flags(dcc[i].user) & BOT_ISOLATE)))
96 tputs(dcc[i].sock, buf, len);
97 }
98
99 void botnet_send_bye()
100 {
101 if (tands > 0) {
102 send_tand_but(-1, "bye\n", 4);
103 #ifndef NO_OLD_BOTNET
104 tandout_but(-1, "bye\n");
105 #endif
106 }
107 }
108
109 void botnet_send_chan(int idx, char *botnick, char *user,
110 int chan, char *data)
111 {
112 int i;
113
114 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
115 if (user) {
116 i = simple_sprintf(OBUF, "c %s@%s %D %s\n", user, botnick, chan, data);
117 } else {
118 i = simple_sprintf(OBUF, "c %s %D %s\n", botnick, chan, data);
119 }
120 send_tand_but(idx, OBUF, -i);
121 #ifndef NO_OLD_BOTNET
122 tandout_but(idx, "chan %s%s%s %d %s\n", user ? user : "",
123 user ? "@" : "", botnick, chan, data);
124 #endif
125 }
126 }
127
128 void botnet_send_act(int idx, char *botnick, char *user,
129 int chan, char *data)
130 {
131 int i;
132
133 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
134 if (user) {
135 i = simple_sprintf(OBUF, "a %s@%s %D %s\n", user, botnick, chan, data);
136 } else {
137 i = simple_sprintf(OBUF, "a %s %D %s\n", botnick, chan, data);
138 }
139 send_tand_but(idx, OBUF, -i);
140 #ifndef NO_OLD_BOTNET
141 tandout_but(idx, "actchan %s%s%s %d %s\n", user ? user : "",
142 user ? "@" : "", botnick, chan, data);
143 #endif
144 }
145 }
146
147 void botnet_send_chat(int idx, char *botnick, char *data)
148 {
149 int i;
150
151 if (tands > 0) {
152 i = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
153 send_tand_but(idx, OBUF, -i);
154 #ifndef NO_OLD_BOTNET
155 tandout_but(idx, "chat %s %s\n", botnick, data);
156 #endif
157 }
158 }
159
160 void botnet_send_ping(int idx)
161 {
162 #ifndef NO_OLD_BOTNET
163 if (b_numver(idx) < NEAT_BOTNET)
164 tputs(dcc[idx].sock, "ping\n", 5);
165 else
166 #endif
167 tputs(dcc[idx].sock, "pi\n", 3);
168 }
169
170 void botnet_send_pong(int idx)
171 {
172 #ifndef NO_OLD_BOTNET
173 if (b_numver(idx) < NEAT_BOTNET)
174 tputs(dcc[idx].sock, "pong\n", 5);
175 else
176 #endif
177 tputs(dcc[idx].sock, "po\n", 3);
178 }
179
180 void botnet_send_priv EGG_VARARGS_DEF(int, arg1)
181 {
182 int idx, l;
183 char *from, *to, *tobot, *format;
184 char tbuf[1024];
185 va_list va;
186
187 idx = EGG_VARARGS_START(int, arg1, va);
188 from = va_arg(va, char *);
189 to = va_arg(va, char *);
190 tobot = va_arg(va, char *);
191 format = va_arg(va, char *);
192 vsnprintf(tbuf, 450, format, va);
193 va_end(va);
194 tbuf[sizeof(tbuf)-1] = 0;
195
196 if (tobot) {
197 #ifndef NO_OLD_BOTNET
198 if (b_numver(idx) < NEAT_BOTNET)
199 l = simple_sprintf(OBUF, "priv %s %s@%s %s\n", from, to, tobot, tbuf);
200 else
201 #endif
202 l = simple_sprintf(OBUF, "p %s %s@%s %s\n", from, to, tobot, tbuf);
203 } else {
204 #ifndef NO_OLD_BOTNET
205 if (b_numver(idx) < NEAT_BOTNET)
206 l = simple_sprintf(OBUF, "priv %s %s %s\n", from, to, tbuf);
207 else
208 #endif
209 l = simple_sprintf(OBUF, "p %s %s %s\n", from, to, tbuf);
210 }
211 tputs(dcc[idx].sock, OBUF, l);
212 }
213
214 void botnet_send_who(int idx, char *from, char *to, int chan)
215 {
216 int l;
217
218 #ifndef NO_OLD_BOTNET
219 if (b_numver(idx) < NEAT_BOTNET)
220 l = simple_sprintf(OBUF, "who %s %s %d\n", from, to, chan);
221 else
222 #endif
223 l = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
224 tputs(dcc[idx].sock, OBUF, l);
225 }
226
227 void botnet_send_infoq(int idx, char *par)
228 {
229 int i = simple_sprintf(OBUF, "i? %s\n", par);
230
231 send_tand_but(idx, OBUF, i);
232 #ifndef NO_OLD_BOTNET
233 tandout_but(idx, "info? %s\n", par);
234 #endif
235 }
236
237 void botnet_send_unlink(int idx, char *who, char *via,
238 char *bot, char *reason)
239 {
240 int l;
241
242 #ifndef NO_OLD_BOTNET
243 if (b_numver(idx) < NEAT_BOTNET)
244 l = simple_sprintf(OBUF, "unlink %s %s %s %s\n", who, via, bot, reason);
245 else
246 #endif
247 l = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
248 tputs(dcc[idx].sock, OBUF, l);
249 }
250
251 void botnet_send_link(int idx, char *who, char *via, char *bot)
252 {
253 int l;
254
255 #ifndef NO_OLD_BOTNET
256 if (b_numver(idx) < NEAT_BOTNET)
257 l = simple_sprintf(OBUF, "link %s %s %s\n", who, via, bot);
258 else
259 #endif
260 l = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
261 tputs(dcc[idx].sock, OBUF, l);
262 }
263
264 void botnet_send_unlinked(int idx, char *bot, char *args)
265 {
266 int l;
267
268 if (tands > 0) {
269 l = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
270 send_tand_but(idx, OBUF, l);
271 #ifndef NO_OLD_BOTNET
272 if ((idx >= 0) && (b_numver(idx) >= NEAT_BOTNET) && args && args[0])
273 tandout_but(idx, "chat %s %s\n", lastbot(bot), args);
274 tandout_but(idx, "unlinked %s\n", bot);
275 #endif
276 }
277 }
278
279 void botnet_send_nlinked(int idx, char *bot, char *next, char flag,
280 int vernum)
281 {
282 int l;
283
284 if (tands > 0) {
285 l = simple_sprintf(OBUF, "n %s %s %c%D\n", bot, next, flag, vernum);
286 send_tand_but(idx, OBUF, l);
287 #ifndef NO_OLD_BOTNET
288 if (flag == '!') {
289 flag = '-';
290 tandout_but(idx, "chat %s %s %s\n", next, _("Linked to"), bot);
291 }
292 tandout_but(idx, "nlinked %s %s %c%d\n", bot, next, flag, vernum);
293 #endif
294 }
295 }
296
297 void botnet_send_traced(int idx, char *bot, char *buf)
298 {
299 int l;
300
301 #ifndef NO_OLD_BOTNET
302 if (b_numver(idx) < NEAT_BOTNET)
303 l = simple_sprintf(OBUF, "traced %s %s\n", bot, buf);
304 else
305 #endif
306 l = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
307 tputs(dcc[idx].sock, OBUF, l);
308 }
309
310 void botnet_send_trace(int idx, char *to, char *from, char *buf)
311 {
312 int l;
313
314 #ifndef NO_OLD_BOTNET
315 if (b_numver(idx) < NEAT_BOTNET)
316 l = simple_sprintf(OBUF, "trace %s %s %s:%s\n", to, from, buf, botnetnick);
317 else
318 #endif
319 l = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, botnetnick);
320 tputs(dcc[idx].sock, OBUF, l);
321 }
322
323 void botnet_send_update(int idx, tand_t * ptr)
324 {
325 int l;
326
327 if (tands > 0) {
328 l = simple_sprintf(OBUF, "u %s %c%D\n", ptr->bot, ptr->share, ptr->ver);
329 send_tand_but(idx, OBUF, l);
330 #ifndef NO_OLD_BOTNET
331 tandout_but(idx, "update %s %c%d\n", ptr->bot, ptr->share, ptr->ver);
332 #endif
333 }
334 }
335
336 void botnet_send_reject(int idx, char *fromp, char *frombot, char *top,
337 char *tobot, char *reason)
338 {
339 int l;
340 char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
341
342 if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
343 if (tobot) {
344 simple_sprintf(to, "%s@%s", top, tobot);
345 top = to;
346 }
347 if (frombot) {
348 simple_sprintf(from, "%s@%s", fromp, frombot);
349 fromp = from;
350 }
351 if (!reason)
352 reason = "";
353 #ifndef NO_OLD_BOTNET
354 if (b_numver(idx) < NEAT_BOTNET)
355 l = simple_sprintf(OBUF, "reject %s %s %s\n", fromp, top, reason);
356 else
357 #endif
358 l = simple_sprintf(OBUF, "r %s %s %s\n", fromp, top, reason);
359 tputs(dcc[idx].sock, OBUF, l);
360 }
361 }
362
363 void botnet_send_zapf(int idx, char *a, char *b, char *c)
364 {
365 int l;
366
367 #ifndef NO_OLD_BOTNET
368 if (b_numver(idx) < NEAT_BOTNET)
369 l = simple_sprintf(OBUF, "zapf %s %s %s\n", a, b, c);
370 else
371 #endif
372 l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
373 tputs(dcc[idx].sock, OBUF, l);
374 }
375
376 void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
377 {
378 int l;
379
380 if (tands > 0) {
381 l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
382 send_tand_but(idx, OBUF, l);
383 #ifndef NO_OLD_BOTNET
384 tandout_but(idx, "zapf-broad %s\n", OBUF + 3);
385 #endif
386 }
387 }
388
389 void botnet_send_motd(int idx, char *from, char *to)
390 {
391 int l;
392
393 #ifndef NO_OLD_BOTNET
394 if (b_numver(idx) < NEAT_BOTNET)
395 l = simple_sprintf(OBUF, "motd %s %s\n", from, to);
396 else
397 #endif
398 l = simple_sprintf(OBUF, "m %s %s\n", from, to);
399 tputs(dcc[idx].sock, OBUF, l);
400 }
401
402 void botnet_send_filereject(int idx, char *path, char *from, char *reason)
403 {
404 int l;
405
406 #ifndef NO_OLD_BOTNET
407 if (b_numver(idx) < NEAT_BOTNET)
408 l = simple_sprintf(OBUF, "filereject %s %s %s\n", path, from, reason);
409 else
410 #endif
411 l = simple_sprintf(OBUF, "f! %s %s %s\n", path, from, reason);
412 tputs(dcc[idx].sock, OBUF, l);
413 }
414
415 void botnet_send_filesend(int idx, char *path, char *from, char *data)
416 {
417 int l;
418
419 #ifndef NO_OLD_BOTNET
420 if (b_numver(idx) < NEAT_BOTNET)
421 l = simple_sprintf(OBUF, "filesend %s %s %s\n", path, from, data);
422 else
423 #endif
424 l = simple_sprintf(OBUF, "fs %s %s %s\n", path, from, data);
425 tputs(dcc[idx].sock, OBUF, l);
426 }
427
428 void botnet_send_filereq(int idx, char *from, char *bot, char *path)
429 {
430 int l;
431
432 #ifndef NO_OLD_BOTNET
433 if (b_numver(idx) < NEAT_BOTNET)
434 l = simple_sprintf(OBUF, "filereq %s %s:%s\n", from, bot, path);
435 else
436 #endif
437 l = simple_sprintf(OBUF, "fr %s %s:%s\n", from, bot, path);
438 tputs(dcc[idx].sock, OBUF, l);
439 }
440
441 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
442 {
443 int l;
444
445 if (tands > 0) {
446 l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle,
447 away ? away : "");
448 send_tand_but(idx, OBUF, -l);
449 #ifndef NO_OLD_BOTNET
450 if (away && away[0])
451 tandout_but(idx, "away %s %d %s\n", bot, sock, away);
452 tandout_but(idx, "idle %s %d %d\n", bot, sock, idle);
453 #endif
454 }
455 }
456
457 void botnet_send_away(int idx, char *bot, int sock,
458 char *msg, int linking)
459 {
460 int l;
461
462 if (tands > 0) {
463 l = simple_sprintf(OBUF, "aw %s%s %D %s\n",
464 ((idx >= 0) && linking) ? "!" : "",
465 bot, sock, msg ? msg : "");
466 send_tand_but(idx, OBUF, -l);
467 #ifndef NO_OLD_BOTNET
468 if (msg) {
469 if (idx < 0) {
470 tandout_but(idx, "chan %s %d %s is now away: %s.\n", bot,
471 dcc[linking].u.chat->channel, dcc[linking].nick,
472 msg);
473 } else if ((b_numver(idx) >= NEAT_BOTNET)) {
474 int partyidx = getparty(bot, sock);
475
476 if (partyidx >= 0)
477 tandout_but(idx, "chan %s %d %s %s: %s.\n", bot,
478 party[partyidx].chan, party[partyidx].nick,
479 _("is now away"), msg);
480 }
481 tandout_but(idx, "away %s %d %s\n", bot, sock, msg);
482 } else {
483 if (idx < 0) {
484 tandout_but(idx, "chan %s %d %s %s.\n", bot,
485 dcc[linking].u.chat->channel, dcc[linking].nick,
486 _("is no longer away"));
487 } else if (b_numver(idx) >= NEAT_BOTNET) {
488 int partyidx = getparty(bot, sock);
489
490 if (partyidx >= 0)
491 tandout_but(idx, "chan %s %d %s %s.\n", bot,
492 party[partyidx].chan, party[partyidx].nick,
493 _("is no longer away"));
494 }
495 tandout_but(idx, "unaway %s %d\n", bot, sock);
496 }
497 #endif
498 }
499 }
500
501 void botnet_send_join_idx(int useridx, int oldchan)
502 {
503 int l;
504
505 if (tands > 0) {
506 l = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
507 botnetnick, dcc[useridx].nick,
508 dcc[useridx].u.chat->channel, geticon(dcc[useridx].user),
509 dcc[useridx].sock, dcc[useridx].host);
510 send_tand_but(-1, OBUF, -l);
511 #ifndef NO_OLD_BOTNET
512 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
513 dcc[useridx].nick, dcc[useridx].u.chat->channel,
514 geticon(dcc[useridx].user), dcc[useridx].sock,
515 dcc[useridx].host);
516 tandout_but(-1, "chan %s %d %s %s %s.\n",
517 botnetnick, dcc[useridx].u.chat->channel,
518 dcc[useridx].nick, _("has joined the"),
519 dcc[useridx].u.chat->channel ? "channel" : "party line");
520 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS)) {
521 tandout_but(-1, "chan %s %d %s %s %s.\n",
522 botnetnick, oldchan,
523 dcc[useridx].nick, _("has left the"),
524 oldchan ? "channel" : "party line");
525 }
526 #endif
527 }
528 }
529
530 void botnet_send_join_party(int idx, int linking, int useridx, int oldchan)
531 {
532 int l;
533
534 if (tands > 0) {
535 l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
536 party[useridx].bot, party[useridx].nick,
537 party[useridx].chan, party[useridx].flag,
538 party[useridx].sock,
539 party[useridx].from ? party[useridx].from : "");
540 send_tand_but(idx, OBUF, -l);
541 #ifndef NO_OLD_BOTNET
542 tandout_but(idx, "join %s %s %d %c%d %s\n", party[useridx].bot,
543 party[useridx].nick, party[useridx].chan,
544 party[useridx].flag, party[useridx].sock,
545 party[useridx].from ? party[useridx].from : "");
546 if ((idx < 0) || (!linking && (b_numver(idx) >= NEAT_BOTNET))) {
547 tandout_but(idx, "chan %s %d %s %s %s.\n",
548 party[useridx].bot, party[useridx].chan,
549 party[useridx].nick, _("has joined the"),
550 party[useridx].chan ? "channel" : "party line");
551 }
552 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS) &&
553 ((idx < 0) || (b_numver(idx) >= NEAT_BOTNET))) {
554 tandout_but(idx, "chan %s %d %s %s %s.\n",
555 party[useridx].bot, oldchan, party[useridx].nick,
556 _("has left the"),
557 party[useridx].chan ? "channel" : "party line");
558 }
559 #endif
560 }
561 }
562
563 void botnet_send_part_idx(int useridx, char *reason)
564 {
565 int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", botnetnick,
566 dcc[useridx].nick, dcc[useridx].sock,
567 reason ? reason : "");
568
569 if (tands > 0) {
570 send_tand_but(-1, OBUF, -l);
571 #ifndef NO_OLD_BOTNET
572 tandout_but(-1, "part %s %s %d\n", botnetnick,
573 dcc[useridx].nick, dcc[useridx].sock);
574 tandout_but(-1, "chan %s %d %s has left the %s%s%s.\n",
575 botnetnick, dcc[useridx].u.chat->channel,
576 dcc[useridx].nick,
577 dcc[useridx].u.chat->channel ? "channel" : "party line",
578 reason ? ": " : "", reason ? reason : "");
579 #endif
580 }
581 }
582
583 void botnet_send_part_party(int idx, int partyidx, char *reason,
584 int silent)
585 {
586 int l;
587
588 if (tands > 0) {
589 l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
590 silent ? "!" : "", party[partyidx].bot,
591 party[partyidx].nick, party[partyidx].sock,
592 reason ? reason : "");
593 send_tand_but(idx, OBUF, -l);
594 #ifndef NO_OLD_BOTNET
595 tandout_but(idx, "part %s %s %d\n", party[partyidx].bot,
596 party[partyidx].nick, party[partyidx].sock);
597 if (((idx < 0) || (b_numver(idx) >= NEAT_BOTNET)) && !silent) {
598 tandout_but(idx, "chan %s %d %s has left the %s%s%s.\n",
599 party[partyidx].bot, party[partyidx].chan,
600 party[partyidx].nick,
601 party[partyidx].chan ? "channel" : "party line",
602 reason ? ": " : "", reason ? reason : "");
603 }
604 #endif
605 }
606 }
607
608 void botnet_send_nkch(int useridx, char *oldnick)
609 {
610 int l;
611
612 if (tands > 0) {
613 l = simple_sprintf(OBUF, "nc %s %D %s\n", botnetnick,
614 dcc[useridx].sock, dcc[useridx].nick);
615 send_tand_but(-1, OBUF, -l);
616 #ifndef NO_OLD_BOTNET
617 tandout_but(-1, "part %s %s %d\n", botnetnick,
618 dcc[useridx].nick, dcc[useridx].sock);
619 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
620 dcc[useridx].nick, dcc[useridx].u.chat->channel,
621 geticon(dcc[useridx].user), dcc[useridx].sock,
622 dcc[useridx].host);
623 tandout_but(-1, "chan %s %d %s: %s -> %s.\n",
624 botnetnick, dcc[useridx].u.chat->channel,
625 oldnick, _("Nick Change:"), dcc[useridx].nick);
626 #endif
627 }
628 }
629
630 void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
631 {
632 int l;
633
634 if (tands > 0) {
635 l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
636 party[useridx].sock, party[useridx].nick);
637 send_tand_but(butidx, OBUF, -l);
638 #ifndef NO_OLD_BOTNET
639 tandout_but(butidx, "part %s %s %d\n", party[useridx].bot,
640 party[useridx].nick, party[useridx].sock);
641 tandout_but(butidx, "join %s %s %d %c%d %s\n", party[useridx].bot,
642 party[useridx].nick, party[useridx].chan,
643 party[useridx].flag, party[useridx].sock,
644 party[useridx].from ? party[useridx].from : "");
645 tandout_but(butidx, "chan %s %d %s : %s -> %s.\n",
646 party[useridx].bot, party[useridx].chan,
647 _("Nick Change:"),
648 oldnick, party[useridx].nick);
649 #endif
650 }
651 }
652
653 /* This part of add_note is more relevant to the botnet than
654 * to the notes file
655 */
656 int add_note(char *to, char *from, char *msg, int idx, int echo)
657 {
658 int status, i, iaway, sock;
659 char *p, botf[81], ss[81], ssf[81];
660 struct userrec *u;
661
662 if (strlen(msg) > 450)
663 msg[450] = 0; /* Notes have a limit */
664 /* note length + PRIVMSG header + nickname + date must be <512 */
665 p = strchr(to, '@');
666 if (p != NULL) { /* Cross-bot note */
667 char x[21];
668
669 *p = 0;
670 strncpy(x, to, 20);
671 x[20] = 0;
672 *p = '@';
673 p++;
674 if (!strcasecmp(p, botnetnick)) /* To me?? */
675 return add_note(x, from, msg, idx, echo); /* Start over, dimwit. */
676 if (strcasecmp(from, botnetnick)) {
677 if (strlen(from) > 40)
678 from[40] = 0;
679 if (strchr(from, '@')) {
680 strcpy(botf, from);
681 } else
682 sprintf(botf, "%s@%s", from, botnetnick);
683 } else
684 strcpy(botf, botnetnick);
685 i = nextbot(p);
686 if (i < 0) {
687 if (idx >= 0)
688 dprintf(idx, _("That bot isnt here.\n"));
689 return NOTE_ERROR;
690 }
691 if ((idx >= 0) && (echo))
692 dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
693 if (idx >= 0) {
694 sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
695 botnet_send_priv(i, ssf, x, p, "%s", msg);
696 } else
697 botnet_send_priv(i, botf, x, p, "%s", msg);
698 return NOTE_OK; /* Forwarded to the right bot */
699 }
700 /* Might be form "sock:nick" */
701 splitc(ssf, from, ':');
702 rmspace(ssf);
703 splitc(ss, to, ':');
704 rmspace(ss);
705 if (!ss[0])
706 sock = (-1);
707 else
708 sock = atoi(ss);
709 /* Don't process if there's a note binding for it */
710 if (idx != (-2)) { /* Notes from bots don't trigger it */
711 if (check_bind_note(from, to, msg)) {
712 if ((idx >= 0) && (echo))
713 dprintf(idx, "-> %s: %s\n", to, msg);
714 return NOTE_TCL;
715 }
716 }
717 if (!(u = get_user_by_handle(userlist, to))) {
718 if (idx >= 0)
719 dprintf(idx, _("I dont know anyone by that name.\n"));
720 return NOTE_ERROR;
721 }
722 if (is_bot(u)) {
723 if (idx >= 0)
724 dprintf(idx, _("Thats a bot. You cant leave notes for a bot.\n"));
725 return NOTE_ERROR;
726 }
727 if (match_noterej(u, from)) {
728 if (idx >= 0)
729 dprintf(idx, "%s %s\n", u->handle, "rejected your note.");
730 return NOTE_REJECT;
731 }
732 status = NOTE_STORED;
733 iaway = 0;
734 /* Online right now? */
735 for (i = 0; i < dcc_total; i++) {
736 if (dcc[i].type && (dcc[i].type->flags & DCT_GETNOTES) &&
737 ((sock == (-1)) || (sock == dcc[i].sock)) &&
738 (!strcasecmp(dcc[i].nick, to))) {
739 int aok = 1;
740
741 if (dcc[i].type == &DCC_CHAT)
742 if ((dcc[i].u.chat->away != NULL) &&
743 (idx != (-2))) {
744 /* Only check away if it's not from a bot */
745 aok = 0;
746 if (idx >= 0)
747 dprintf(idx, "%s %s: %s\n", dcc[i].nick, _("is away"),
748 dcc[i].u.chat->away);
749 if (!iaway)
750 iaway = i;
751 status = NOTE_AWAY;
752 }
753 if (aok) {
754 char *p, *fr = from;
755 int l = 0;
756 char work[1024];
757
758 while ((*msg == '<') || (*msg == '>')) {
759 p = newsplit(&msg);
760 if (*p == '<')
761 l += simple_sprintf(work + l, "via %s, ", p + 1);
762 else if (*from == '@')
763 fr = p + 1;
764 }
765 if (idx == -2 || (!strcasecmp(from, botnetnick)))
766 dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
767 else
768 dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
769 if ((idx >= 0) && (echo))
770 dprintf(idx, "-> %s: %s\n", to, msg);
771 return NOTE_OK;
772 }
773 }
774 }
775 if (idx == (-2))
776 return NOTE_OK; /* Error msg from a tandembot: don't store */
777 status = storenote(from, to, msg, idx, NULL, 0);
778 if (status < 0) status = NOTE_ERROR;
779 else if (status == NOTE_AWAY) {
780 /* User is away in all sessions -- just notify the user that a
781 * message arrived and was stored. (only oldest session is notified.)
782 */
783 dprintf(iaway, "*** %s.\n", _("Note arrived for you"));
784 }
785 return(status);
786 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23