botmsg.c 16 KB

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