botmsg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. #include "main.h"
  2. #include "tandem.h"
  3. extern struct dcc_t *dcc;
  4. extern int dcc_total, tands, sgrab;
  5. extern char botnetnick[];
  6. extern time_t now;
  7. extern party_t *party;
  8. extern Tcl_Interp *interp;
  9. extern struct userrec *userlist;
  10. static char OBUF[1024];
  11. static char tobase64array[64] =
  12. { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  14. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
  15. '5', '6', '7', '8', '9', '[', ']' };
  16. char *
  17. int_to_base64 (unsigned int val)
  18. {
  19. static char buf_base64[12];
  20. int i = 11;
  21. buf_base64[11] = 0;
  22. if (!val)
  23. {
  24. buf_base64[10] = 'A';
  25. return buf_base64 + 10;
  26. }
  27. while (val)
  28. {
  29. i--;
  30. buf_base64[i] = tobase64array[val & 0x3f];
  31. val = val >> 6;
  32. }
  33. return buf_base64 + i;
  34. }
  35. char *
  36. int_to_base10 (int val)
  37. {
  38. static char buf_base10[17];
  39. int p = 0;
  40. int i = 16;
  41. buf_base10[16] = 0;
  42. if (!val)
  43. {
  44. buf_base10[15] = '0';
  45. return buf_base10 + 15;
  46. }
  47. if (val < 0)
  48. {
  49. p = 1;
  50. val *= -1;
  51. }
  52. while (val)
  53. {
  54. i--;
  55. buf_base10[i] = '0' + (val % 10);
  56. val /= 10;
  57. }
  58. if (p)
  59. {
  60. i--;
  61. buf_base10[i] = '-';
  62. }
  63. return buf_base10 + i;
  64. }
  65. char *
  66. unsigned_int_to_base10 (unsigned int val)
  67. {
  68. static char buf_base10[16];
  69. int i = 15;
  70. buf_base10[15] = 0;
  71. if (!val)
  72. {
  73. buf_base10[14] = '0';
  74. return buf_base10 + 14;
  75. }
  76. while (val)
  77. {
  78. i--;
  79. buf_base10[i] = '0' + (val % 10);
  80. val /= 10;
  81. }
  82. return buf_base10 + i;
  83. }
  84. int simple_sprintf
  85. EGG_VARARGS_DEF (char *, arg1)
  86. {
  87. char *buf, *format, *s;
  88. int c = 0, i;
  89. va_list va;
  90. buf = EGG_VARARGS_START (char *, arg1, va);
  91. format = va_arg (va, char *);
  92. while (*format && c < 1023)
  93. {
  94. if (*format == '%')
  95. {
  96. format++;
  97. switch (*format)
  98. {
  99. case 's':
  100. s = va_arg (va, char *);
  101. break;
  102. case 'd':
  103. case 'i':
  104. i = va_arg (va, int);
  105. s = int_to_base10 (i);
  106. break;
  107. case 'D':
  108. i = va_arg (va, int);
  109. s = int_to_base64 ((unsigned int) i);
  110. break;
  111. case 'u':
  112. i = va_arg (va, unsigned int);
  113. s = unsigned_int_to_base10 (i);
  114. break;
  115. case '%':
  116. buf[c++] = *format++;
  117. continue;
  118. case 'c':
  119. buf[c++] = (char) va_arg (va, int);
  120. format++;
  121. continue;
  122. default:
  123. continue;
  124. }
  125. if (s)
  126. while (*s && c < 1023)
  127. buf[c++] = *s++;
  128. format++;
  129. }
  130. else
  131. buf[c++] = *format++;
  132. }
  133. va_end (va);
  134. buf[c] = 0;
  135. return c;
  136. }
  137. void
  138. send_tand_but (int x, char *buf, int len)
  139. {
  140. int i, iso = 0;
  141. if (len < 0)
  142. {
  143. len = -len;
  144. iso = 1;
  145. }
  146. for (i = 0; i < dcc_total; i++)
  147. if ((dcc[i].type == &DCC_BOT) && (i != x) && (b_numver (i) >= NEAT_BOTNET)
  148. && (!iso || !(bot_flags (dcc[i].user) & BOT_ISOLATE)))
  149. tputs (dcc[i].sock, buf, len);
  150. }
  151. #ifdef S_DCCPASS
  152. void
  153. botnet_send_cmdpass (int idx, char *cmd, char *pass)
  154. {
  155. char *buf;
  156. if (tands > 0)
  157. {
  158. buf = nmalloc (strlen (cmd) + strlen (pass) + 10);
  159. sprintf (buf, "cp %s %s\n", cmd, pass);
  160. send_tand_but (idx, buf, strlen (buf));
  161. nfree (buf);
  162. }
  163. }
  164. #endif
  165. int
  166. botnet_send_cmd (char *fbot, char *bot, char *from, int fromidx, char *cmd)
  167. {
  168. int i = nextbot (bot);
  169. if (i >= 0)
  170. {
  171. char buf[2048];
  172. sprintf (buf, STR ("rc %s %s %s %i %s\n"), bot, fbot, from, fromidx,
  173. cmd);
  174. tputs (dcc[i].sock, buf, strlen (buf));
  175. return 1;
  176. }
  177. else if (!strcmp (bot, botnetnick))
  178. {
  179. char tmp[24];
  180. sprintf (tmp, "%i", fromidx);
  181. gotremotecmd (botnetnick, botnetnick, from, tmp, cmd);
  182. }
  183. return 0;
  184. }
  185. void
  186. botnet_send_cmd_broad (int idx, char *fbot, char *from, int fromidx,
  187. char *cmd)
  188. {
  189. if (tands > 0)
  190. {
  191. char buf[2048];
  192. sprintf (buf, STR ("rc * %s %s %i %s\n"), fbot, from, fromidx, cmd);
  193. send_tand_but (idx, buf, strlen (buf));
  194. }
  195. if (idx < 0)
  196. {
  197. char tmp[24];
  198. sprintf (tmp, "%i", fromidx);
  199. gotremotecmd ("*", botnetnick, from, tmp, cmd);
  200. }
  201. } void
  202. botnet_send_cmdreply (char *fbot, char *bot, char *to, char *toidx, char *ln)
  203. {
  204. int i = nextbot (bot);
  205. if (i >= 0)
  206. {
  207. char buf[2048];
  208. sprintf (buf, STR ("rr %s %s %s %s %s\n"), bot, fbot, to, toidx, ln);
  209. tputs (dcc[i].sock, buf, strlen (buf));
  210. }
  211. else if (!strcmp (bot, botnetnick))
  212. {
  213. gotremotereply (botnetnick, to, toidx, ln);
  214. }
  215. }
  216. void
  217. botnet_send_bye ()
  218. {
  219. if (tands > 0)
  220. {
  221. send_tand_but (-1, "bye\n", 4);
  222. }
  223. }
  224. void
  225. botnet_send_chan (int idx, char *botnick, char *user, int chan, char *data)
  226. {
  227. int i;
  228. if ((tands > 0) && (chan < GLOBAL_CHANS))
  229. {
  230. if (user)
  231. {
  232. i =
  233. simple_sprintf (OBUF, "c %s@%s %D %s\n", user, botnick, chan,
  234. data);
  235. }
  236. else
  237. {
  238. i = simple_sprintf (OBUF, "c %s %D %s\n", botnick, chan, data);
  239. }
  240. send_tand_but (idx, OBUF, -i);
  241. }
  242. }
  243. void
  244. botnet_send_act (int idx, char *botnick, char *user, int chan, char *data)
  245. {
  246. int i;
  247. if ((tands > 0) && (chan < GLOBAL_CHANS))
  248. {
  249. if (user)
  250. {
  251. i =
  252. simple_sprintf (OBUF, "a %s@%s %D %s\n", user, botnick, chan,
  253. data);
  254. }
  255. else
  256. {
  257. i = simple_sprintf (OBUF, "a %s %D %s\n", botnick, chan, data);
  258. }
  259. send_tand_but (idx, OBUF, -i);
  260. }
  261. }
  262. void
  263. botnet_send_chat (int idx, char *botnick, char *data)
  264. {
  265. int i;
  266. if (tands > 0)
  267. {
  268. i = simple_sprintf (OBUF, "ct %s %s\n", botnick, data);
  269. send_tand_but (idx, OBUF, -i);
  270. }
  271. }
  272. void
  273. botnet_send_ping (int idx)
  274. {
  275. tputs (dcc[idx].sock, "pi\n", 3);
  276. dcc[idx].pingtime = now;
  277. } void
  278. botnet_send_pong (int idx)
  279. {
  280. tputs (dcc[idx].sock, "po\n", 3);
  281. } void botnet_send_priv
  282. EGG_VARARGS_DEF (int, arg1)
  283. {
  284. int idx, l;
  285. char *from, *to, *tobot, *format;
  286. char tbuf[1024];
  287. va_list va;
  288. idx = EGG_VARARGS_START (int, arg1, va);
  289. from = va_arg (va, char *);
  290. to = va_arg (va, char *);
  291. tobot = va_arg (va, char *);
  292. format = va_arg (va, char *);
  293. egg_vsnprintf (tbuf, 450, format, va);
  294. va_end (va);
  295. tbuf[sizeof (tbuf) - 1] = 0;
  296. if (tobot)
  297. {
  298. l = simple_sprintf (OBUF, "p %s %s@%s %s\n", from, to, tobot, tbuf);
  299. }
  300. else
  301. {
  302. l = simple_sprintf (OBUF, "p %s %s %s\n", from, to, tbuf);
  303. }
  304. tputs (dcc[idx].sock, OBUF, l);
  305. }
  306. void
  307. botnet_send_who (int idx, char *from, char *to, int chan)
  308. {
  309. int l;
  310. l = simple_sprintf (OBUF, "w %s %s %D\n", from, to, chan);
  311. tputs (dcc[idx].sock, OBUF, l);
  312. } void
  313. botnet_send_infoq (int idx, char *par)
  314. {
  315. int i = simple_sprintf (OBUF, "i? %s\n", par);
  316. send_tand_but (idx, OBUF, i);
  317. } void
  318. botnet_send_unlink (int idx, char *who, char *via, char *bot, char *reason)
  319. {
  320. int l;
  321. l = simple_sprintf (OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
  322. tputs (dcc[idx].sock, OBUF, l);
  323. } void
  324. botnet_send_link (int idx, char *who, char *via, char *bot)
  325. {
  326. int l;
  327. l = simple_sprintf (OBUF, "l %s %s %s\n", who, via, bot);
  328. tputs (dcc[idx].sock, OBUF, l);
  329. } void
  330. botnet_send_unlinked (int idx, char *bot, char *args)
  331. {
  332. int l;
  333. if (tands > 0)
  334. {
  335. l = simple_sprintf (OBUF, "un %s %s\n", bot, args ? args : "");
  336. send_tand_but (idx, OBUF, l);
  337. }
  338. }
  339. void
  340. botnet_send_nlinked (int idx, char *bot, char *next, char flag, int vernum)
  341. {
  342. int l;
  343. if (tands > 0)
  344. {
  345. l = simple_sprintf (OBUF, "n %s %s %c%D\n", bot, next, flag, vernum);
  346. send_tand_but (idx, OBUF, l);
  347. }
  348. }
  349. void
  350. botnet_send_traced (int idx, char *bot, char *buf)
  351. {
  352. int l;
  353. l = simple_sprintf (OBUF, "td %s %s\n", bot, buf);
  354. tputs (dcc[idx].sock, OBUF, l);
  355. } void
  356. botnet_send_trace (int idx, char *to, char *from, char *buf)
  357. {
  358. int l;
  359. l = simple_sprintf (OBUF, "t %s %s %s:%s\n", to, from, buf, botnetnick);
  360. tputs (dcc[idx].sock, OBUF, l);
  361. } void
  362. botnet_send_update (int idx, tand_t * ptr)
  363. {
  364. int l;
  365. if (tands > 0)
  366. {
  367. l =
  368. simple_sprintf (OBUF, "u %s %c%D\n", ptr->bot, ptr->share, ptr->ver);
  369. send_tand_but (idx, OBUF, l);
  370. }
  371. }
  372. void
  373. botnet_send_reject (int idx, char *fromp, char *frombot, char *top,
  374. char *tobot, char *reason)
  375. {
  376. int l;
  377. char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
  378. if (!(bot_flags (dcc[idx].user) & BOT_ISOLATE))
  379. {
  380. if (tobot)
  381. {
  382. simple_sprintf (to, "%s@%s", top, tobot);
  383. top = to;
  384. }
  385. if (frombot)
  386. {
  387. simple_sprintf (from, "%s@%s", fromp, frombot);
  388. fromp = from;
  389. }
  390. if (!reason)
  391. reason = "";
  392. l = simple_sprintf (OBUF, "r %s %s %s\n", fromp, top, reason);
  393. tputs (dcc[idx].sock, OBUF, l);
  394. }
  395. }
  396. void
  397. putbot (char *bot, char *par)
  398. {
  399. int i;
  400. char msg[sgrab - 110];
  401. if (!bot[0] || !par[0])
  402. return;
  403. i = nextbot (bot);
  404. if (i < 0)
  405. return;
  406. strncpyz (msg, par, sizeof msg);
  407. botnet_send_zapf (i, botnetnick, bot, msg);
  408. }
  409. void
  410. botnet_send_zapf (int idx, char *a, char *b, char *c)
  411. {
  412. int l;
  413. l = simple_sprintf (OBUF, "z %s %s %s\n", a, b, c);
  414. tputs (dcc[idx].sock, OBUF, l);
  415. } void
  416. botnet_send_cfg (int idx, struct cfg_entry *entry)
  417. {
  418. int l;
  419. l =
  420. simple_sprintf (OBUF, STR ("cg %s %s\n"), entry->name,
  421. entry->gdata ? entry->gdata : "");
  422. tputs (dcc[idx].sock, OBUF, l);
  423. } void
  424. botnet_send_cfg_broad (int idx, struct cfg_entry *entry)
  425. {
  426. int l;
  427. if (tands > 0)
  428. {
  429. l =
  430. simple_sprintf (OBUF, STR ("cg %s %s\n"), entry->name,
  431. entry->gdata ? entry->gdata : "");
  432. send_tand_but (idx, OBUF, l);
  433. }
  434. }
  435. void
  436. botnet_send_zapf_broad (int idx, char *a, char *b, char *c)
  437. {
  438. int l;
  439. if (tands > 0)
  440. {
  441. l =
  442. simple_sprintf (OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "",
  443. c);
  444. send_tand_but (idx, OBUF, l);
  445. }
  446. }
  447. void
  448. botnet_send_hublog_f (int idx, char *a, char *b, int type)
  449. {
  450. int l;
  451. if (tands > 0)
  452. {
  453. l = simple_sprintf (OBUF, "hl %s %i %s\n", a, type, b);
  454. send_tand_but (idx, OBUF, l);
  455. }
  456. }
  457. void
  458. botnet_send_hublog (int idx, char *a, char *b)
  459. {
  460. int l;
  461. if (tands > 0)
  462. {
  463. l = simple_sprintf (OBUF, "hl %s %s\n", a, b);
  464. send_tand_but (idx, OBUF, l);
  465. }
  466. }
  467. void
  468. botnet_send_filereject (int idx, char *path, char *from, char *reason)
  469. {
  470. int l;
  471. l = simple_sprintf (OBUF, "f! %s %s %s\n", path, from, reason);
  472. tputs (dcc[idx].sock, OBUF, l);
  473. } void
  474. botnet_send_filesend (int idx, char *path, char *from, char *data)
  475. {
  476. int l;
  477. l = simple_sprintf (OBUF, "fs %s %s %s\n", path, from, data);
  478. tputs (dcc[idx].sock, OBUF, l);
  479. } void
  480. botnet_send_filereq (int idx, char *from, char *bot, char *path)
  481. {
  482. int l;
  483. l = simple_sprintf (OBUF, "fr %s %s:%s\n", from, bot, path);
  484. tputs (dcc[idx].sock, OBUF, l);
  485. } void
  486. botnet_send_idle (int idx, char *bot, int sock, int idle, char *away)
  487. {
  488. int l;
  489. if (tands > 0)
  490. {
  491. l =
  492. simple_sprintf (OBUF, "i %s %D %D %s\n", bot, sock, idle,
  493. away ? away : "");
  494. send_tand_but (idx, OBUF, -l);
  495. }
  496. }
  497. void
  498. botnet_send_away (int idx, char *bot, int sock, char *msg, int linking)
  499. {
  500. int l;
  501. if (tands > 0)
  502. {
  503. l =
  504. simple_sprintf (OBUF, "aw %s%s %D %s\n",
  505. ((idx >= 0)
  506. && linking) ? "!" : "", bot, sock, msg ? msg : "");
  507. send_tand_but (idx, OBUF, -l);
  508. }
  509. }
  510. void
  511. botnet_send_join_idx (int useridx, int oldchan)
  512. {
  513. int l;
  514. if (tands > 0)
  515. {
  516. l =
  517. simple_sprintf (OBUF, "j %s %s %D %c%D %s\n", botnetnick,
  518. dcc[useridx].nick, dcc[useridx].u.chat->channel,
  519. geticon (useridx), dcc[useridx].sock,
  520. dcc[useridx].host);
  521. send_tand_but (-1, OBUF, -l);
  522. }
  523. }
  524. void
  525. botnet_send_join_party (int idx, int linking, int useridx, int oldchan)
  526. {
  527. int l;
  528. if (tands > 0)
  529. {
  530. l =
  531. simple_sprintf (OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
  532. party[useridx].bot, party[useridx].nick,
  533. party[useridx].chan, party[useridx].flag,
  534. party[useridx].sock,
  535. party[useridx].from ? party[useridx].from : "");
  536. send_tand_but (idx, OBUF, -l);
  537. }
  538. }
  539. void
  540. botnet_send_part_idx (int useridx, char *reason)
  541. {
  542. int l =
  543. simple_sprintf (OBUF, "pt %s %s %D %s\n", botnetnick, dcc[useridx].nick,
  544. dcc[useridx].sock, reason ? reason : "");
  545. if (tands > 0)
  546. {
  547. send_tand_but (-1, OBUF, -l);
  548. }
  549. }
  550. void
  551. botnet_send_part_party (int idx, int partyidx, char *reason, int silent)
  552. {
  553. int l;
  554. if (tands > 0)
  555. {
  556. l =
  557. simple_sprintf (OBUF, "pt %s%s %s %D %s\n", silent ? "!" : "",
  558. party[partyidx].bot, party[partyidx].nick,
  559. party[partyidx].sock, reason ? reason : "");
  560. send_tand_but (idx, OBUF, -l);
  561. }
  562. }
  563. void
  564. botnet_send_nkch (int useridx, char *oldnick)
  565. {
  566. int l;
  567. if (tands > 0)
  568. {
  569. l =
  570. simple_sprintf (OBUF, "nc %s %D %s\n", botnetnick, dcc[useridx].sock,
  571. dcc[useridx].nick);
  572. send_tand_but (-1, OBUF, -l);
  573. }
  574. }
  575. void
  576. botnet_send_nkch_part (int butidx, int useridx, char *oldnick)
  577. {
  578. int l;
  579. if (tands > 0)
  580. {
  581. l =
  582. simple_sprintf (OBUF, "nc %s %D %s\n", party[useridx].bot,
  583. party[useridx].sock, party[useridx].nick);
  584. send_tand_but (butidx, OBUF, -l);
  585. }
  586. }
  587. int
  588. add_note (char *to, char *from, char *msg, int idx, int echo)
  589. {
  590. int status, i, iaway, sock;
  591. char *p, botf[81], ss[81], ssf[81];
  592. struct userrec *u;
  593. if (strlen (msg) > 450)
  594. msg[450] = 0;
  595. p = strchr (to, '@');
  596. if (p != NULL)
  597. {
  598. char x[21];
  599. *p = 0;
  600. strncpy (x, to, 20);
  601. x[20] = 0;
  602. *p = '@';
  603. p++;
  604. if (!egg_strcasecmp (p, botnetnick))
  605. return add_note (x, from, msg, idx, echo);
  606. if (egg_strcasecmp (from, botnetnick))
  607. {
  608. if (strlen (from) > 40)
  609. from[40] = 0;
  610. if (strchr (from, '@'))
  611. {
  612. strcpy (botf, from);
  613. }
  614. else
  615. sprintf (botf, "%s@%s", from, botnetnick);
  616. }
  617. else
  618. strcpy (botf, botnetnick);
  619. i = nextbot (p);
  620. if (i < 0)
  621. {
  622. if (idx >= 0)
  623. dprintf (idx, BOT_NOTHERE);
  624. return NOTE_ERROR;
  625. }
  626. if ((idx >= 0) && (echo))
  627. dprintf (idx, "-> %s@%s: %s\n", x, p, msg);
  628. if (idx >= 0)
  629. {
  630. sprintf (ssf, "%lu:%s", dcc[idx].sock, botf);
  631. botnet_send_priv (i, ssf, x, p, "%s", msg);
  632. }
  633. else
  634. botnet_send_priv (i, botf, x, p, "%s", msg);
  635. return NOTE_OK;
  636. }
  637. splitc (ssf, from, ':');
  638. rmspace (ssf);
  639. splitc (ss, to, ':');
  640. rmspace (ss);
  641. if (!ss[0])
  642. sock = (-1);
  643. else
  644. sock = atoi (ss);
  645. if (idx != (-2))
  646. {
  647. if (check_tcl_note (from, to, msg))
  648. {
  649. if ((idx >= 0) && (echo))
  650. dprintf (idx, "-> %s: %s\n", to, msg);
  651. return NOTE_TCL;
  652. }
  653. }
  654. if (!(u = get_user_by_handle (userlist, to)))
  655. {
  656. if (idx >= 0)
  657. dprintf (idx, USERF_UNKNOWN);
  658. return NOTE_ERROR;
  659. }
  660. if (is_bot (u))
  661. {
  662. if (idx >= 0)
  663. dprintf (idx, BOT_NONOTES);
  664. return NOTE_ERROR;
  665. }
  666. if (match_noterej (u, from))
  667. {
  668. if (idx >= 0)
  669. dprintf (idx, "%s %s\n", u->handle, "rejected your note.");
  670. return NOTE_REJECT;
  671. }
  672. status = NOTE_STORED;
  673. iaway = 0;
  674. for (i = 0; i < dcc_total; i++)
  675. {
  676. if ((dcc[i].type->flags & DCT_GETNOTES)
  677. && ((sock == (-1)) || (sock == dcc[i].sock))
  678. && (!egg_strcasecmp (dcc[i].nick, to)))
  679. {
  680. int aok = 1;
  681. if (dcc[i].type == &DCC_CHAT)
  682. if ((dcc[i].u.chat->away != NULL) && (idx != (-2)))
  683. {
  684. aok = 0;
  685. if (idx >= 0)
  686. dprintf (idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
  687. dcc[i].u.chat->away);
  688. if (!iaway)
  689. iaway = i;
  690. status = NOTE_AWAY;
  691. }
  692. if (aok)
  693. {
  694. char *p, *fr = from;
  695. int l = 0;
  696. char work[1024];
  697. while ((*msg == '<') || (*msg == '>'))
  698. {
  699. p = newsplit (&msg);
  700. if (*p == '<')
  701. l += simple_sprintf (work + l, "via %s, ", p + 1);
  702. else if (*from == '@')
  703. fr = p + 1;
  704. }
  705. if (idx == -2 || (!egg_strcasecmp (from, botnetnick)))
  706. dprintf (i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
  707. else
  708. dprintf (i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
  709. if ((idx >= 0) && (echo))
  710. dprintf (idx, "-> %s: %s\n", to, msg);
  711. return NOTE_OK;
  712. }
  713. }
  714. }
  715. if (idx == (-2))
  716. return NOTE_OK;
  717. Tcl_SetVar (interp, "_from", from, 0);
  718. Tcl_SetVar (interp, "_to", to, 0);
  719. Tcl_SetVar (interp, "_data", msg, 0);
  720. simple_sprintf (ss, "%d", dcc[idx].sock);
  721. Tcl_SetVar (interp, "_idx", ss, 0);
  722. if (Tcl_VarEval (interp, "storenote", " $_from $_to $_data $_idx", NULL) ==
  723. TCL_OK)
  724. {
  725. if (interp->result && interp->result[0])
  726. status = NOTE_FWD;
  727. if (status == NOTE_AWAY)
  728. {
  729. dprintf (iaway, "*** %s.\n", BOT_NOTEARRIVED);
  730. }
  731. return status;
  732. }
  733. return NOTE_ERROR;
  734. }