00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "main.h"
00030 #include "tandem.h"
00031
00032 extern struct dcc_t *dcc;
00033 extern int dcc_total, tands;
00034 extern char botnetnick[];
00035 extern party_t *party;
00036 extern Tcl_Interp *interp;
00037 extern struct userrec *userlist;
00038
00039 static char OBUF[1024];
00040
00041
00042 #ifndef NO_OLD_BOTNET
00043
00044
00045 void tandout_but EGG_VARARGS_DEF(int, arg1)
00046 {
00047 int i, x, len;
00048 char *format;
00049 char s[601];
00050 va_list va;
00051
00052 x = EGG_VARARGS_START(int, arg1, va);
00053 format = va_arg(va, char *);
00054
00055 egg_vsnprintf(s, 511, format, va);
00056 va_end(va);
00057 s[sizeof(s) - 1] = 0;
00058
00059 len = strlen(s);
00060
00061 for (i = 0; i < dcc_total; i++)
00062 if ((dcc[i].type == &DCC_BOT) && (i != x) && (b_numver(i) < NEAT_BOTNET))
00063 tputs(dcc[i].sock, s, len);
00064 }
00065 #endif
00066
00067
00068 static char tobase64array[64] = {
00069 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
00070 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
00071 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
00072 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
00073 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
00074 '[', ']'
00075 };
00076
00077 char *int_to_base64(unsigned int val)
00078 {
00079 static char buf_base64[12];
00080 int i = 11;
00081
00082 buf_base64[11] = 0;
00083 if (!val) {
00084 buf_base64[10] = 'A';
00085 return buf_base64 + 10;
00086 }
00087 while (val) {
00088 i--;
00089 buf_base64[i] = tobase64array[val & 0x3f];
00090 val = val >> 6;
00091 }
00092 return buf_base64 + i;
00093 }
00094
00095 char *int_to_base10(int val)
00096 {
00097 static char buf_base10[17];
00098 int p = 0;
00099 int i = 16;
00100
00101 buf_base10[16] = 0;
00102 if (!val) {
00103 buf_base10[15] = '0';
00104 return buf_base10 + 15;
00105 }
00106 if (val < 0) {
00107 p = 1;
00108 val *= -1;
00109 }
00110 while (val) {
00111 i--;
00112 buf_base10[i] = '0' + (val % 10);
00113 val /= 10;
00114 }
00115 if (p) {
00116 i--;
00117 buf_base10[i] = '-';
00118 }
00119 return buf_base10 + i;
00120 }
00121
00122 char *unsigned_int_to_base10(unsigned int val)
00123 {
00124 static char buf_base10[16];
00125 int i = 15;
00126
00127 buf_base10[15] = 0;
00128 if (!val) {
00129 buf_base10[14] = '0';
00130 return buf_base10 + 14;
00131 }
00132 while (val) {
00133 i--;
00134 buf_base10[i] = '0' + (val % 10);
00135 val /= 10;
00136 }
00137 return buf_base10 + i;
00138 }
00139
00140 int simple_sprintf EGG_VARARGS_DEF(char *, arg1)
00141 {
00142 char *buf, *format, *s;
00143 int c = 0, i;
00144 va_list va;
00145
00146 buf = EGG_VARARGS_START(char *, arg1, va);
00147 format = va_arg(va, char *);
00148
00149 while (*format && c < 1023) {
00150 if (*format == '%') {
00151 format++;
00152 switch (*format) {
00153 case 's':
00154 s = va_arg(va, char *);
00155
00156 break;
00157 case 'd':
00158 case 'i':
00159 i = va_arg(va, int);
00160
00161 s = int_to_base10(i);
00162 break;
00163 case 'D':
00164 i = va_arg(va, int);
00165
00166 s = int_to_base64((unsigned int) i);
00167 break;
00168 case 'u':
00169 i = va_arg(va, unsigned int);
00170
00171 s = unsigned_int_to_base10(i);
00172 break;
00173 case '%':
00174 buf[c++] = *format++;
00175 continue;
00176 case 'c':
00177 buf[c++] = (char) va_arg(va, int);
00178
00179 format++;
00180 continue;
00181 default:
00182 continue;
00183 }
00184 if (s)
00185 while (*s && c < 1023)
00186 buf[c++] = *s++;
00187 format++;
00188 } else
00189 buf[c++] = *format++;
00190 }
00191 va_end(va);
00192 buf[c] = 0;
00193 return c;
00194 }
00195
00196
00197
00198 void send_tand_but(int x, char *buf, int len)
00199 {
00200 int i, iso = 0;
00201
00202 if (len < 0) {
00203 len = -len;
00204 iso = 1;
00205 }
00206 for (i = 0; i < dcc_total; i++)
00207 if ((dcc[i].type == &DCC_BOT) && (i != x) &&
00208 (b_numver(i) >= NEAT_BOTNET) &&
00209 (!iso || !(bot_flags(dcc[i].user) & BOT_ISOLATE)))
00210 tputs(dcc[i].sock, buf, len);
00211 }
00212
00213 void botnet_send_bye()
00214 {
00215 if (tands > 0) {
00216 send_tand_but(-1, "bye\n", 4);
00217 #ifndef NO_OLD_BOTNET
00218 tandout_but(-1, "bye\n");
00219 #endif
00220 }
00221 }
00222
00223 void botnet_send_chan(int idx, char *botnick, char *user, int chan, char *data)
00224 {
00225 int i;
00226
00227 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
00228 if (user) {
00229 i = simple_sprintf(OBUF, "c %s@%s %D %s\n", user, botnick, chan, data);
00230 } else {
00231 i = simple_sprintf(OBUF, "c %s %D %s\n", botnick, chan, data);
00232 }
00233 send_tand_but(idx, OBUF, -i);
00234 #ifndef NO_OLD_BOTNET
00235 tandout_but(idx, "chan %s%s%s %d %s\n", user ? user : "",
00236 user ? "@" : "", botnick, chan, data);
00237 #endif
00238 }
00239 }
00240
00241 void botnet_send_act(int idx, char *botnick, char *user, int chan, char *data)
00242 {
00243 int i;
00244
00245 if ((tands > 0) && (chan < GLOBAL_CHANS)) {
00246 if (user) {
00247 i = simple_sprintf(OBUF, "a %s@%s %D %s\n", user, botnick, chan, data);
00248 } else {
00249 i = simple_sprintf(OBUF, "a %s %D %s\n", botnick, chan, data);
00250 }
00251 send_tand_but(idx, OBUF, -i);
00252 #ifndef NO_OLD_BOTNET
00253 tandout_but(idx, "actchan %s%s%s %d %s\n", user ? user : "",
00254 user ? "@" : "", botnick, chan, data);
00255 #endif
00256 }
00257 }
00258
00259 void botnet_send_chat(int idx, char *botnick, char *data)
00260 {
00261 int i;
00262
00263 if (tands > 0) {
00264 i = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
00265 send_tand_but(idx, OBUF, -i);
00266 #ifndef NO_OLD_BOTNET
00267 tandout_but(idx, "chat %s %s\n", botnick, data);
00268 #endif
00269 }
00270 }
00271
00272 void botnet_send_ping(int idx)
00273 {
00274 #ifndef NO_OLD_BOTNET
00275 if (b_numver(idx) < NEAT_BOTNET)
00276 tputs(dcc[idx].sock, "ping\n", 5);
00277 else
00278 #endif
00279 tputs(dcc[idx].sock, "pi\n", 3);
00280 }
00281
00282 void botnet_send_pong(int idx)
00283 {
00284 #ifndef NO_OLD_BOTNET
00285 if (b_numver(idx) < NEAT_BOTNET)
00286 tputs(dcc[idx].sock, "pong\n", 5);
00287 else
00288 #endif
00289 tputs(dcc[idx].sock, "po\n", 3);
00290 }
00291
00292 void botnet_send_priv EGG_VARARGS_DEF(int, arg1)
00293 {
00294 int idx, l;
00295 char *from, *to, *tobot, *format;
00296 char tbuf[1024];
00297 va_list va;
00298
00299 idx = EGG_VARARGS_START(int, arg1, va);
00300 from = va_arg(va, char *);
00301 to = va_arg(va, char *);
00302 tobot = va_arg(va, char *);
00303 format = va_arg(va, char *);
00304
00305 egg_vsnprintf(tbuf, 450, format, va);
00306 va_end(va);
00307 tbuf[sizeof(tbuf) - 1] = 0;
00308
00309 if (tobot) {
00310 #ifndef NO_OLD_BOTNET
00311 if (b_numver(idx) < NEAT_BOTNET)
00312 l = simple_sprintf(OBUF, "priv %s %s@%s %s\n", from, to, tobot, tbuf);
00313 else
00314 #endif
00315 l = simple_sprintf(OBUF, "p %s %s@%s %s\n", from, to, tobot, tbuf);
00316 } else {
00317 #ifndef NO_OLD_BOTNET
00318 if (b_numver(idx) < NEAT_BOTNET)
00319 l = simple_sprintf(OBUF, "priv %s %s %s\n", from, to, tbuf);
00320 else
00321 #endif
00322 l = simple_sprintf(OBUF, "p %s %s %s\n", from, to, tbuf);
00323 }
00324 tputs(dcc[idx].sock, OBUF, l);
00325 }
00326
00327 void botnet_send_who(int idx, char *from, char *to, int chan)
00328 {
00329 int l;
00330
00331 #ifndef NO_OLD_BOTNET
00332 if (b_numver(idx) < NEAT_BOTNET)
00333 l = simple_sprintf(OBUF, "who %s %s %d\n", from, to, chan);
00334 else
00335 #endif
00336 l = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
00337 tputs(dcc[idx].sock, OBUF, l);
00338 }
00339
00340 void botnet_send_infoq(int idx, char *par)
00341 {
00342 int i = simple_sprintf(OBUF, "i? %s\n", par);
00343
00344 send_tand_but(idx, OBUF, i);
00345 #ifndef NO_OLD_BOTNET
00346 tandout_but(idx, "info? %s\n", par);
00347 #endif
00348 }
00349
00350 void botnet_send_unlink(int idx, char *who, char *via, char *bot, char *reason)
00351 {
00352 int l;
00353
00354 #ifndef NO_OLD_BOTNET
00355 if (b_numver(idx) < NEAT_BOTNET)
00356 l = simple_sprintf(OBUF, "unlink %s %s %s %s\n", who, via, bot, reason);
00357 else
00358 #endif
00359 l = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
00360 tputs(dcc[idx].sock, OBUF, l);
00361 }
00362
00363 void botnet_send_link(int idx, char *who, char *via, char *bot)
00364 {
00365 int l;
00366
00367 #ifndef NO_OLD_BOTNET
00368 if (b_numver(idx) < NEAT_BOTNET)
00369 l = simple_sprintf(OBUF, "link %s %s %s\n", who, via, bot);
00370 else
00371 #endif
00372 l = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
00373 tputs(dcc[idx].sock, OBUF, l);
00374 }
00375
00376 void botnet_send_unlinked(int idx, char *bot, char *args)
00377 {
00378 int l;
00379
00380 if (tands > 0) {
00381 l = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
00382 send_tand_but(idx, OBUF, l);
00383 #ifndef NO_OLD_BOTNET
00384 if ((idx >= 0) && (b_numver(idx) >= NEAT_BOTNET) && args && args[0])
00385 tandout_but(idx, "chat %s %s\n", lastbot(bot), args);
00386 tandout_but(idx, "unlinked %s\n", bot);
00387 #endif
00388 }
00389 }
00390
00391 void botnet_send_nlinked(int idx, char *bot, char *next, char flag, int vernum)
00392 {
00393 int l;
00394
00395 if (tands > 0) {
00396 l = simple_sprintf(OBUF, "n %s %s %c%D\n", bot, next, flag, vernum);
00397 send_tand_but(idx, OBUF, l);
00398 #ifndef NO_OLD_BOTNET
00399 if (flag == '!') {
00400 flag = '-';
00401 tandout_but(idx, "chat %s %s %s\n", next, NET_LINKEDTO, bot);
00402 }
00403 tandout_but(idx, "nlinked %s %s %c%d\n", bot, next, flag, vernum);
00404 #endif
00405 }
00406 }
00407
00408 void botnet_send_traced(int idx, char *bot, char *buf)
00409 {
00410 int l;
00411
00412 #ifndef NO_OLD_BOTNET
00413 if (b_numver(idx) < NEAT_BOTNET)
00414 l = simple_sprintf(OBUF, "traced %s %s\n", bot, buf);
00415 else
00416 #endif
00417 l = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
00418 tputs(dcc[idx].sock, OBUF, l);
00419 }
00420
00421 void botnet_send_trace(int idx, char *to, char *from, char *buf)
00422 {
00423 int l;
00424
00425 #ifndef NO_OLD_BOTNET
00426 if (b_numver(idx) < NEAT_BOTNET)
00427 l = simple_sprintf(OBUF, "trace %s %s %s:%s\n", to, from, buf, botnetnick);
00428 else
00429 #endif
00430 l = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, botnetnick);
00431 tputs(dcc[idx].sock, OBUF, l);
00432 }
00433
00434 void botnet_send_update(int idx, tand_t *ptr)
00435 {
00436 int l;
00437
00438 if (tands > 0) {
00439 l = simple_sprintf(OBUF, "u %s %c%D\n", ptr->bot, ptr->share, ptr->ver);
00440 send_tand_but(idx, OBUF, l);
00441 #ifndef NO_OLD_BOTNET
00442 tandout_but(idx, "update %s %c%d\n", ptr->bot, ptr->share, ptr->ver);
00443 #endif
00444 }
00445 }
00446
00447 void botnet_send_reject(int idx, char *fromp, char *frombot, char *top,
00448 char *tobot, char *reason)
00449 {
00450 int l;
00451 char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
00452
00453 if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
00454 if (tobot) {
00455 simple_sprintf(to, "%s@%s", top, tobot);
00456 top = to;
00457 }
00458 if (frombot) {
00459 simple_sprintf(from, "%s@%s", fromp, frombot);
00460 fromp = from;
00461 }
00462 if (!reason)
00463 reason = "";
00464 #ifndef NO_OLD_BOTNET
00465 if (b_numver(idx) < NEAT_BOTNET)
00466 l = simple_sprintf(OBUF, "reject %s %s %s\n", fromp, top, reason);
00467 else
00468 #endif
00469 l = simple_sprintf(OBUF, "r %s %s %s\n", fromp, top, reason);
00470 tputs(dcc[idx].sock, OBUF, l);
00471 }
00472 }
00473
00474 void botnet_send_zapf(int idx, char *a, char *b, char *c)
00475 {
00476 int l;
00477
00478 #ifndef NO_OLD_BOTNET
00479 if (b_numver(idx) < NEAT_BOTNET)
00480 l = simple_sprintf(OBUF, "zapf %s %s %s\n", a, b, c);
00481 else
00482 #endif
00483 l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
00484 tputs(dcc[idx].sock, OBUF, l);
00485 }
00486
00487 void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
00488 {
00489 int l;
00490
00491 if (tands > 0) {
00492 l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
00493 send_tand_but(idx, OBUF, l);
00494 #ifndef NO_OLD_BOTNET
00495 tandout_but(idx, "zapf-broad %s\n", OBUF + 3);
00496 #endif
00497 }
00498 }
00499
00500 void botnet_send_motd(int idx, char *from, char *to)
00501 {
00502 int l;
00503
00504 #ifndef NO_OLD_BOTNET
00505 if (b_numver(idx) < NEAT_BOTNET)
00506 l = simple_sprintf(OBUF, "motd %s %s\n", from, to);
00507 else
00508 #endif
00509 l = simple_sprintf(OBUF, "m %s %s\n", from, to);
00510 tputs(dcc[idx].sock, OBUF, l);
00511 }
00512
00513 void botnet_send_filereject(int idx, char *path, char *from, char *reason)
00514 {
00515 int l;
00516
00517 #ifndef NO_OLD_BOTNET
00518 if (b_numver(idx) < NEAT_BOTNET)
00519 l = simple_sprintf(OBUF, "filereject %s %s %s\n", path, from, reason);
00520 else
00521 #endif
00522 l = simple_sprintf(OBUF, "f! %s %s %s\n", path, from, reason);
00523 tputs(dcc[idx].sock, OBUF, l);
00524 }
00525
00526 void botnet_send_filesend(int idx, char *path, char *from, char *data)
00527 {
00528 int l;
00529
00530 #ifndef NO_OLD_BOTNET
00531 if (b_numver(idx) < NEAT_BOTNET)
00532 l = simple_sprintf(OBUF, "filesend %s %s %s\n", path, from, data);
00533 else
00534 #endif
00535 l = simple_sprintf(OBUF, "fs %s %s %s\n", path, from, data);
00536 tputs(dcc[idx].sock, OBUF, l);
00537 }
00538
00539 void botnet_send_filereq(int idx, char *from, char *bot, char *path)
00540 {
00541 int l;
00542
00543 #ifndef NO_OLD_BOTNET
00544 if (b_numver(idx) < NEAT_BOTNET)
00545 l = simple_sprintf(OBUF, "filereq %s %s:%s\n", from, bot, path);
00546 else
00547 #endif
00548 l = simple_sprintf(OBUF, "fr %s %s:%s\n", from, bot, path);
00549 tputs(dcc[idx].sock, OBUF, l);
00550 }
00551
00552 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
00553 {
00554 int l;
00555
00556 if (tands > 0) {
00557 l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle,
00558 away ? away : "");
00559 send_tand_but(idx, OBUF, -l);
00560 #ifndef NO_OLD_BOTNET
00561 if (away && away[0])
00562 tandout_but(idx, "away %s %d %s\n", bot, sock, away);
00563 tandout_but(idx, "idle %s %d %d\n", bot, sock, idle);
00564 #endif
00565 }
00566 }
00567
00568 void botnet_send_away(int idx, char *bot, int sock, char *msg, int linking)
00569 {
00570 int l;
00571
00572 if (tands > 0) {
00573 l = simple_sprintf(OBUF, "aw %s%s %D %s\n",
00574 ((idx >= 0) && linking) ? "!" : "",
00575 bot, sock, msg ? msg : "");
00576 send_tand_but(idx, OBUF, -l);
00577 #ifndef NO_OLD_BOTNET
00578 if (msg) {
00579 if (idx < 0) {
00580 tandout_but(idx, "chan %s %d %s is now away: %s.\n", bot,
00581 dcc[linking].u.chat->channel, dcc[linking].nick, msg);
00582 } else if ((b_numver(idx) >= NEAT_BOTNET)) {
00583 int partyidx = getparty(bot, sock);
00584
00585 if (partyidx >= 0)
00586 tandout_but(idx, "chan %s %d %s %s: %s.\n", bot,
00587 party[partyidx].chan, party[partyidx].nick,
00588 NET_AWAY, msg);
00589 }
00590 tandout_but(idx, "away %s %d %s\n", bot, sock, msg);
00591 } else {
00592 if (idx < 0) {
00593 tandout_but(idx, "chan %s %d %s %s.\n", bot,
00594 dcc[linking].u.chat->channel, dcc[linking].nick,
00595 NET_UNAWAY);
00596 } else if (b_numver(idx) >= NEAT_BOTNET) {
00597 int partyidx = getparty(bot, sock);
00598
00599 if (partyidx >= 0)
00600 tandout_but(idx, "chan %s %d %s %s.\n", bot,
00601 party[partyidx].chan, party[partyidx].nick, NET_UNAWAY);
00602 }
00603 tandout_but(idx, "unaway %s %d\n", bot, sock);
00604 }
00605 #endif
00606 }
00607 }
00608
00609 void botnet_send_join_idx(int useridx, int oldchan)
00610 {
00611 int l;
00612
00613 if (tands > 0) {
00614 l = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
00615 botnetnick, dcc[useridx].nick,
00616 dcc[useridx].u.chat->channel, geticon(useridx),
00617 dcc[useridx].sock, dcc[useridx].host);
00618 send_tand_but(-1, OBUF, -l);
00619 #ifndef NO_OLD_BOTNET
00620 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
00621 dcc[useridx].nick, dcc[useridx].u.chat->channel,
00622 geticon(useridx), dcc[useridx].sock, dcc[useridx].host);
00623 tandout_but(-1, "chan %s %d %s %s %s.\n",
00624 botnetnick, dcc[useridx].u.chat->channel,
00625 dcc[useridx].nick, NET_JOINEDTHE,
00626 dcc[useridx].u.chat->channel ? "channel" : "party line");
00627 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS)) {
00628 tandout_but(-1, "chan %s %d %s %s %s.\n",
00629 botnetnick, oldchan,
00630 dcc[useridx].nick, NET_LEFTTHE,
00631 oldchan ? "channel" : "party line");
00632 }
00633 #endif
00634 }
00635 }
00636
00637 void botnet_send_join_party(int idx, int linking, int useridx, int oldchan)
00638 {
00639 int l;
00640
00641 if (tands > 0) {
00642 l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
00643 party[useridx].bot, party[useridx].nick,
00644 party[useridx].chan, party[useridx].flag,
00645 party[useridx].sock,
00646 party[useridx].from ? party[useridx].from : "");
00647 send_tand_but(idx, OBUF, -l);
00648 #ifndef NO_OLD_BOTNET
00649 tandout_but(idx, "join %s %s %d %c%d %s\n", party[useridx].bot,
00650 party[useridx].nick, party[useridx].chan,
00651 party[useridx].flag, party[useridx].sock,
00652 party[useridx].from ? party[useridx].from : "");
00653 if ((idx < 0) || (!linking && (b_numver(idx) >= NEAT_BOTNET))) {
00654 tandout_but(idx, "chan %s %d %s %s %s.\n",
00655 party[useridx].bot, party[useridx].chan,
00656 party[useridx].nick, NET_JOINEDTHE,
00657 party[useridx].chan ? "channel" : "party line");
00658 }
00659 if ((oldchan >= 0) && (oldchan < GLOBAL_CHANS) &&
00660 ((idx < 0) || (b_numver(idx) >= NEAT_BOTNET))) {
00661 tandout_but(idx, "chan %s %d %s %s %s.\n",
00662 party[useridx].bot, oldchan, party[useridx].nick,
00663 NET_LEFTTHE, party[useridx].chan ? "channel" : "party line");
00664 }
00665 #endif
00666 }
00667 }
00668
00669 void botnet_send_part_idx(int useridx, char *reason)
00670 {
00671 int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", botnetnick,
00672 dcc[useridx].nick, dcc[useridx].sock,
00673 reason ? reason : "");
00674
00675 if (tands > 0) {
00676 send_tand_but(-1, OBUF, -l);
00677 #ifndef NO_OLD_BOTNET
00678 tandout_but(-1, "part %s %s %d\n", botnetnick,
00679 dcc[useridx].nick, dcc[useridx].sock);
00680 tandout_but(-1, "chan %s %d %s has left the %s%s%s.\n",
00681 botnetnick, dcc[useridx].u.chat->channel,
00682 dcc[useridx].nick,
00683 dcc[useridx].u.chat->channel ? "channel" : "party line",
00684 reason ? ": " : "", reason ? reason : "");
00685 #endif
00686 }
00687 }
00688
00689 void botnet_send_part_party(int idx, int partyidx, char *reason, int silent)
00690 {
00691 int l;
00692
00693 if (tands > 0) {
00694 l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
00695 silent ? "!" : "", party[partyidx].bot,
00696 party[partyidx].nick, party[partyidx].sock,
00697 reason ? reason : "");
00698 send_tand_but(idx, OBUF, -l);
00699 #ifndef NO_OLD_BOTNET
00700 tandout_but(idx, "part %s %s %d\n", party[partyidx].bot,
00701 party[partyidx].nick, party[partyidx].sock);
00702 if (((idx < 0) || (b_numver(idx) >= NEAT_BOTNET)) && !silent) {
00703 tandout_but(idx, "chan %s %d %s has left the %s%s%s.\n",
00704 party[partyidx].bot, party[partyidx].chan,
00705 party[partyidx].nick,
00706 party[partyidx].chan ? "channel" : "party line",
00707 reason ? ": " : "", reason ? reason : "");
00708 }
00709 #endif
00710 }
00711 }
00712
00713 void botnet_send_nkch(int useridx, char *oldnick)
00714 {
00715 int l;
00716
00717 if (tands > 0) {
00718 l = simple_sprintf(OBUF, "nc %s %D %s\n", botnetnick,
00719 dcc[useridx].sock, dcc[useridx].nick);
00720 send_tand_but(-1, OBUF, -l);
00721 #ifndef NO_OLD_BOTNET
00722 tandout_but(-1, "part %s %s %d\n", botnetnick,
00723 dcc[useridx].nick, dcc[useridx].sock);
00724 tandout_but(-1, "join %s %s %d %c%d %s\n", botnetnick,
00725 dcc[useridx].nick, dcc[useridx].u.chat->channel,
00726 geticon(useridx), dcc[useridx].sock, dcc[useridx].host);
00727 tandout_but(-1, "chan %s %d %s: %s -> %s.\n",
00728 botnetnick, dcc[useridx].u.chat->channel,
00729 oldnick, NET_NICKCHANGE, dcc[useridx].nick);
00730 #endif
00731 }
00732 }
00733
00734 void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
00735 {
00736 int l;
00737
00738 if (tands > 0) {
00739 l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
00740 party[useridx].sock, party[useridx].nick);
00741 send_tand_but(butidx, OBUF, -l);
00742 #ifndef NO_OLD_BOTNET
00743 tandout_but(butidx, "part %s %s %d\n", party[useridx].bot,
00744 party[useridx].nick, party[useridx].sock);
00745 tandout_but(butidx, "join %s %s %d %c%d %s\n", party[useridx].bot,
00746 party[useridx].nick, party[useridx].chan,
00747 party[useridx].flag, party[useridx].sock,
00748 party[useridx].from ? party[useridx].from : "");
00749 tandout_but(butidx, "chan %s %d %s : %s -> %s.\n",
00750 party[useridx].bot, party[useridx].chan,
00751 NET_NICKCHANGE, oldnick, party[useridx].nick);
00752 #endif
00753 }
00754 }
00755
00756
00757
00758
00759 int add_note(char *to, char *from, char *msg, int idx, int echo)
00760 {
00761 int status, i, iaway, sock;
00762 char *p, botf[81], ss[81], ssf[81];
00763 struct userrec *u;
00764
00765
00766
00767
00768 if (strlen(msg) > 450)
00769 msg[450] = 0;
00770
00771
00772
00773
00774 p = strchr(to, '@');
00775 if (p != NULL) {
00776 char x[21];
00777
00778 *p = 0;
00779 strncpy(x, to, 20);
00780 x[20] = 0;
00781 *p = '@';
00782 p++;
00783
00784 if (!egg_strcasecmp(p, botnetnick))
00785 return add_note(x, from, msg, idx, echo);
00786
00787 if (egg_strcasecmp(from, botnetnick)) {
00788 if (strlen(from) > 40)
00789 from[40] = 0;
00790
00791 if (strchr(from, '@')) {
00792 strcpy(botf, from);
00793 } else
00794 sprintf(botf, "%s@%s", from, botnetnick);
00795
00796 } else
00797 strcpy(botf, botnetnick);
00798
00799 i = nextbot(p);
00800 if (i < 0) {
00801 if (idx >= 0)
00802 dprintf(idx, BOT_NOTHERE);
00803
00804 return NOTE_ERROR;
00805 }
00806
00807 if (idx >= 0 && echo)
00808 dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
00809
00810 if (idx >= 0) {
00811 sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
00812 botnet_send_priv(i, ssf, x, p, "%s", msg);
00813 } else
00814 botnet_send_priv(i, botf, x, p, "%s", msg);
00815
00816 return NOTE_OK;
00817 }
00818
00819
00820 splitc(ssf, from, ':');
00821 rmspace(ssf);
00822 splitc(ss, to, ':');
00823 rmspace(ss);
00824 if (!ss[0])
00825 sock = -1;
00826 else
00827 sock = atoi(ss);
00828
00829
00830 if (idx != -2) {
00831 if (check_tcl_note(from, to, msg)) {
00832 if (idx >= 0 && echo)
00833 dprintf(idx, "-> %s: %s\n", to, msg);
00834
00835 return NOTE_TCL;
00836 }
00837 }
00838
00839
00840 u = get_user_by_handle(userlist, to);
00841 if (!u) {
00842 if (idx >= 0)
00843 dprintf(idx, USERF_UNKNOWN);
00844
00845 return NOTE_ERROR;
00846 }
00847
00848
00849 if (is_bot(u)) {
00850 if (idx >= 0)
00851 dprintf(idx, BOT_NONOTES);
00852
00853 return NOTE_ERROR;
00854 }
00855
00856
00857 if (match_noterej(u, from)) {
00858 if (idx >= 0)
00859 dprintf(idx, "%s rejected your note.\n", u->handle);
00860
00861 return NOTE_REJECT;
00862 }
00863
00864 status = NOTE_STORED;
00865 iaway = 0;
00866
00867
00868 for (i = 0; i < dcc_total; i++) {
00869 if ((dcc[i].type->flags & DCT_GETNOTES) &&
00870 (sock == -1 || sock == dcc[i].sock) &&
00871 !egg_strcasecmp(dcc[i].nick, to)) {
00872 int aok = 1;
00873
00874 if (dcc[i].type == &DCC_CHAT) {
00875
00876
00877 if (dcc[i].u.chat->away != NULL && idx != -2) {
00878 aok = 0;
00879
00880 if (idx >= 0)
00881 dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
00882 dcc[i].u.chat->away);
00883
00884 if (!iaway)
00885 iaway = i;
00886 status = NOTE_AWAY;
00887 }
00888 }
00889
00890 if (aok) {
00891 char *p, *fr = from, work[1024];
00892 int l = 0;
00893
00894 while (*msg == '<' || *msg == '>') {
00895 p = newsplit(&msg);
00896
00897 if (*p == '<')
00898 l += simple_sprintf(work + l, "via %s, ", p + 1);
00899 else if (*from == '@')
00900 fr = p + 1;
00901 }
00902
00903 if (idx == -2 || !egg_strcasecmp(from, botnetnick))
00904 dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
00905 else
00906 dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
00907
00908 if (idx >= 0 && echo)
00909 dprintf(idx, "-> %s: %s\n", to, msg);
00910
00911 return NOTE_OK;
00912 }
00913 }
00914 }
00915
00916 if (idx == -2)
00917 return NOTE_OK;
00918
00919
00920 simple_sprintf(ss, "%d", (idx >= 0) ? dcc[idx].sock : -1);
00921 Tcl_SetVar(interp, "_from", from, 0);
00922 Tcl_SetVar(interp, "_to", to, 0);
00923 Tcl_SetVar(interp, "_data", msg, 0);
00924 Tcl_SetVar(interp, "_idx", ss, 0);
00925 if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) ==
00926 TCL_OK) {
00927
00928 if (!tcl_resultempty())
00929 status = NOTE_FWD;
00930
00931
00932
00933
00934 if (status == NOTE_AWAY)
00935 dprintf(iaway, "*** %s.\n", BOT_NOTEARRIVED);
00936
00937 return status;
00938 }
00939
00940
00941 return NOTE_ERROR;
00942 }