botmsg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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) + 5 + 1);
  155. sprintf(buf, "cp %s %s\n", cmd, pass);
  156. send_tand_but(idx, buf, strlen(buf));
  157. nfree(buf);
  158. }
  159. }
  160. #endif /* S_DCCPASS */
  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. void botnet_send_chan(int idx, char *botnick, char *user, int chan, char *data)
  203. {
  204. int i;
  205. if ((tands > 0) && (chan < GLOBAL_CHANS)) {
  206. if (user) {
  207. i = simple_sprintf(OBUF, "c %s@%s %D %s\n", user, botnick, chan, data);
  208. } else {
  209. i = simple_sprintf(OBUF, "c %s %D %s\n", botnick, chan, data);
  210. }
  211. send_tand_but(idx, OBUF, -i);
  212. }
  213. }
  214. void botnet_send_act(int idx, char *botnick, char *user, int chan, char *data)
  215. {
  216. int i;
  217. if ((tands > 0) && (chan < GLOBAL_CHANS)) {
  218. if (user) {
  219. i = simple_sprintf(OBUF, "a %s@%s %D %s\n", user, botnick, chan, data);
  220. } else {
  221. i = simple_sprintf(OBUF, "a %s %D %s\n", botnick, chan, data);
  222. }
  223. send_tand_but(idx, OBUF, -i);
  224. }
  225. }
  226. void botnet_send_chat(int idx, char *botnick, char *data)
  227. {
  228. int i;
  229. if (tands > 0) {
  230. i = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
  231. send_tand_but(idx, OBUF, -i);
  232. }
  233. }
  234. void botnet_send_ping(int idx)
  235. {
  236. tputs(dcc[idx].sock, "pi\n", 3);
  237. dcc[idx].pingtime = now;
  238. }
  239. void botnet_send_pong(int idx)
  240. {
  241. tputs(dcc[idx].sock, "po\n", 3);
  242. }
  243. void botnet_send_priv EGG_VARARGS_DEF(int, arg1)
  244. {
  245. int idx, l;
  246. char *from, *to, *tobot, *format;
  247. char tbuf[1024];
  248. va_list va;
  249. idx = EGG_VARARGS_START(int, arg1, va);
  250. from = va_arg(va, char *);
  251. to = va_arg(va, char *);
  252. tobot = va_arg(va, char *);
  253. format = va_arg(va, char *);
  254. egg_vsnprintf(tbuf, 450, format, va);
  255. va_end(va);
  256. tbuf[sizeof(tbuf)-1] = 0;
  257. if (tobot) {
  258. l = simple_sprintf(OBUF, "p %s %s@%s %s\n", from, to, tobot, tbuf);
  259. } else {
  260. l = simple_sprintf(OBUF, "p %s %s %s\n", from, to, tbuf);
  261. }
  262. tputs(dcc[idx].sock, OBUF, l);
  263. }
  264. void botnet_send_who(int idx, char *from, char *to, int chan)
  265. {
  266. int l;
  267. l = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
  268. tputs(dcc[idx].sock, OBUF, l);
  269. }
  270. void botnet_send_infoq(int idx, char *par)
  271. {
  272. int i = simple_sprintf(OBUF, "i? %s\n", par);
  273. send_tand_but(idx, OBUF, i);
  274. }
  275. void botnet_send_unlink(int idx, char *who, char *via,
  276. char *bot, char *reason)
  277. {
  278. int l;
  279. l = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
  280. tputs(dcc[idx].sock, OBUF, l);
  281. }
  282. void botnet_send_link(int idx, char *who, char *via, char *bot)
  283. {
  284. int l;
  285. l = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
  286. tputs(dcc[idx].sock, OBUF, l);
  287. }
  288. void botnet_send_unlinked(int idx, char *bot, char *args)
  289. {
  290. int l;
  291. if (tands > 0) {
  292. l = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
  293. send_tand_but(idx, OBUF, l);
  294. }
  295. }
  296. void botnet_send_nlinked(int idx, char *bot, char *next, char flag,
  297. int vernum)
  298. {
  299. int l;
  300. if (tands > 0) {
  301. l = simple_sprintf(OBUF, "n %s %s %c%D\n", bot, next, flag, vernum);
  302. send_tand_but(idx, OBUF, l);
  303. }
  304. }
  305. void botnet_send_traced(int idx, char *bot, char *buf)
  306. {
  307. int l;
  308. l = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
  309. tputs(dcc[idx].sock, OBUF, l);
  310. }
  311. void botnet_send_trace(int idx, char *to, char *from, char *buf)
  312. {
  313. int l;
  314. l = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, botnetnick);
  315. tputs(dcc[idx].sock, OBUF, l);
  316. }
  317. void botnet_send_update(int idx, tand_t * ptr)
  318. {
  319. int l;
  320. if (tands > 0) {
  321. l = simple_sprintf(OBUF, "u %s %c%D\n", ptr->bot, ptr->share, ptr->ver);
  322. send_tand_but(idx, OBUF, l);
  323. }
  324. }
  325. void botnet_send_reject(int idx, char *fromp, char *frombot, char *top, char *tobot, char *reason)
  326. {
  327. int l;
  328. char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
  329. if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
  330. if (tobot) {
  331. simple_sprintf(to, "%s@%s", top, tobot);
  332. top = to;
  333. }
  334. if (frombot) {
  335. simple_sprintf(from, "%s@%s", fromp, frombot);
  336. fromp = from;
  337. }
  338. if (!reason)
  339. reason = "";
  340. l = simple_sprintf(OBUF, "r %s %s %s\n", fromp, top, reason);
  341. tputs(dcc[idx].sock, OBUF, l);
  342. }
  343. }
  344. void putallbots(char *par)
  345. {
  346. char msg[SGRAB-110];
  347. if (!par || !par[0])
  348. return;
  349. strncpyz(msg, par, sizeof msg);
  350. botnet_send_zapf_broad(-1, botnetnick, NULL, msg);
  351. }
  352. void putbot(char *bot, char *par)
  353. {
  354. int i;
  355. char msg[SGRAB-110];
  356. if (!bot || !par || !bot[0] || !par[0])
  357. return;
  358. i = nextbot(bot);
  359. if (i < 0)
  360. return;
  361. strncpyz(msg, par, sizeof msg);
  362. botnet_send_zapf(i, botnetnick, bot, msg);
  363. }
  364. void botnet_send_zapf(int idx, char *a, char *b, char *c)
  365. {
  366. int l;
  367. l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
  368. tputs(dcc[idx].sock, OBUF, l);
  369. }
  370. void botnet_send_cfg(int idx, struct cfg_entry * entry) {
  371. int l;
  372. l = simple_sprintf(OBUF, STR("cg %s %s\n"), entry->name, entry->gdata ? entry->gdata : "");
  373. tputs(dcc[idx].sock, OBUF, l);
  374. }
  375. void botnet_send_cfg_broad(int idx, struct cfg_entry * entry) {
  376. int l;
  377. if (tands > 0) {
  378. l = simple_sprintf(OBUF, STR("cg %s %s\n"), entry->name, entry->gdata ? entry->gdata : "");
  379. send_tand_but(idx, OBUF, l);
  380. }
  381. }
  382. void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
  383. {
  384. int l;
  385. if (tands > 0) {
  386. l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
  387. send_tand_but(idx, OBUF, l);
  388. }
  389. }
  390. void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
  391. {
  392. int l;
  393. if (tands > 0) {
  394. l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle,
  395. away ? away : "");
  396. send_tand_but(idx, OBUF, -l);
  397. }
  398. }
  399. void botnet_send_away(int idx, char *bot, int sock,
  400. char *msg, int linking)
  401. {
  402. int l;
  403. if (tands > 0) {
  404. l = simple_sprintf(OBUF, "aw %s%s %D %s\n",
  405. ((idx >= 0) && linking) ? "!" : "",
  406. bot, sock, msg ? msg : "");
  407. send_tand_but(idx, OBUF, -l);
  408. }
  409. }
  410. void botnet_send_join_idx(int useridx, int oldchan)
  411. {
  412. int l;
  413. if (tands > 0) {
  414. l = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
  415. botnetnick, dcc[useridx].nick,
  416. dcc[useridx].u.chat->channel, geticon(useridx),
  417. dcc[useridx].sock, dcc[useridx].host);
  418. send_tand_but(-1, OBUF, -l);
  419. }
  420. }
  421. void botnet_send_join_party(int idx, int linking, int useridx, int oldchan)
  422. {
  423. int l;
  424. if (tands > 0) {
  425. l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
  426. party[useridx].bot, party[useridx].nick,
  427. party[useridx].chan, party[useridx].flag,
  428. party[useridx].sock,
  429. party[useridx].from ? party[useridx].from : "");
  430. send_tand_but(idx, OBUF, -l);
  431. }
  432. }
  433. void botnet_send_part_idx(int useridx, char *reason)
  434. {
  435. int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", botnetnick,
  436. dcc[useridx].nick, dcc[useridx].sock,
  437. reason ? reason : "");
  438. if (tands > 0) {
  439. send_tand_but(-1, OBUF, -l);
  440. }
  441. }
  442. void botnet_send_part_party(int idx, int partyidx, char *reason,
  443. int silent)
  444. {
  445. int l;
  446. if (tands > 0) {
  447. l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
  448. silent ? "!" : "", party[partyidx].bot,
  449. party[partyidx].nick, party[partyidx].sock,
  450. reason ? reason : "");
  451. send_tand_but(idx, OBUF, -l);
  452. }
  453. }
  454. void botnet_send_nkch(int useridx, char *oldnick)
  455. {
  456. int l;
  457. if (tands > 0) {
  458. l = simple_sprintf(OBUF, "nc %s %D %s\n", botnetnick,
  459. dcc[useridx].sock, dcc[useridx].nick);
  460. send_tand_but(-1, OBUF, -l);
  461. }
  462. }
  463. void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
  464. {
  465. int l;
  466. if (tands > 0) {
  467. l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
  468. party[useridx].sock, party[useridx].nick);
  469. send_tand_but(butidx, OBUF, -l);
  470. }
  471. }
  472. /* This part of add_note is more relevant to the botnet than
  473. * to the notes file
  474. */
  475. int add_note(char *to, char *from, char *msg, int idx, int echo)
  476. {
  477. int status, i, iaway, sock;
  478. char *p, botf[81], ss[81], ssf[81];
  479. struct userrec *u;
  480. if (strlen(msg) > 450)
  481. msg[450] = 0; /* Notes have a limit */
  482. /* note length + PRIVMSG header + nickname + date must be <512 */
  483. p = strchr(to, '@');
  484. if (p != NULL) { /* Cross-bot note */
  485. char x[21];
  486. *p = 0;
  487. strncpy(x, to, 20);
  488. x[20] = 0;
  489. *p = '@';
  490. p++;
  491. if (!egg_strcasecmp(p, botnetnick)) /* To me?? */
  492. return add_note(x, from, msg, idx, echo); /* Start over, dimwit. */
  493. if (egg_strcasecmp(from, botnetnick)) {
  494. if (strlen(from) > 40)
  495. from[40] = 0;
  496. if (strchr(from, '@')) {
  497. strcpy(botf, from);
  498. } else
  499. sprintf(botf, "%s@%s", from, botnetnick);
  500. } else
  501. strcpy(botf, botnetnick);
  502. i = nextbot(p);
  503. if (i < 0) {
  504. if (idx >= 0)
  505. dprintf(idx, BOT_NOTHERE);
  506. return NOTE_ERROR;
  507. }
  508. if ((idx >= 0) && (echo))
  509. dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
  510. if (idx >= 0) {
  511. sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
  512. botnet_send_priv(i, ssf, x, p, "%s", msg);
  513. } else
  514. botnet_send_priv(i, botf, x, p, "%s", msg);
  515. return NOTE_OK; /* Forwarded to the right bot */
  516. }
  517. /* Might be form "sock:nick" */
  518. splitc(ssf, from, ':');
  519. rmspace(ssf);
  520. splitc(ss, to, ':');
  521. rmspace(ss);
  522. if (!ss[0])
  523. sock = (-1);
  524. else
  525. sock = atoi(ss);
  526. /* Don't process if there's a note binding for it */
  527. if (idx != (-2)) { /* Notes from bots don't trigger it */
  528. if (check_tcl_note(from, to, msg)) {
  529. if ((idx >= 0) && (echo))
  530. dprintf(idx, "-> %s: %s\n", to, msg);
  531. return NOTE_TCL;
  532. }
  533. }
  534. if (!(u = get_user_by_handle(userlist, to))) {
  535. if (idx >= 0)
  536. dprintf(idx, USERF_UNKNOWN);
  537. return NOTE_ERROR;
  538. }
  539. if (is_bot(u)) {
  540. if (idx >= 0)
  541. dprintf(idx, BOT_NONOTES);
  542. return NOTE_ERROR;
  543. }
  544. if (match_noterej(u, from)) {
  545. if (idx >= 0)
  546. dprintf(idx, "%s %s\n", u->handle, "rejected your note.");
  547. return NOTE_REJECT;
  548. }
  549. status = NOTE_STORED;
  550. iaway = 0;
  551. /* Online right now? */
  552. for (i = 0; i < dcc_total; i++) {
  553. if ((dcc[i].type->flags & DCT_GETNOTES) &&
  554. ((sock == (-1)) || (sock == dcc[i].sock)) &&
  555. (!egg_strcasecmp(dcc[i].nick, to))) {
  556. int aok = 1;
  557. if (dcc[i].type == &DCC_CHAT)
  558. if ((dcc[i].u.chat->away != NULL) &&
  559. (idx != (-2))) {
  560. /* Only check away if it's not from a bot */
  561. aok = 0;
  562. if (idx >= 0)
  563. dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
  564. dcc[i].u.chat->away);
  565. if (!iaway)
  566. iaway = i;
  567. status = NOTE_AWAY;
  568. }
  569. if (aok) {
  570. char *p, *fr = from;
  571. int l = 0;
  572. char work[1024];
  573. while ((*msg == '<') || (*msg == '>')) {
  574. p = newsplit(&msg);
  575. if (*p == '<')
  576. l += simple_sprintf(work + l, "via %s, ", p + 1);
  577. else if (*from == '@')
  578. fr = p + 1;
  579. }
  580. if (idx == -2 || (!egg_strcasecmp(from, botnetnick)))
  581. dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
  582. else
  583. dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
  584. if ((idx >= 0) && (echo))
  585. dprintf(idx, "-> %s: %s\n", to, msg);
  586. return NOTE_OK;
  587. }
  588. }
  589. }
  590. if (idx == (-2))
  591. return NOTE_OK; /* Error msg from a tandembot: don't store */
  592. /* Call store note here */
  593. Tcl_SetVar(interp, "_from", from, 0);
  594. Tcl_SetVar(interp, "_to", to, 0);
  595. Tcl_SetVar(interp, "_data", msg, 0);
  596. simple_sprintf(ss, "%d", dcc[idx].sock);
  597. Tcl_SetVar(interp, "_idx", ss, 0);
  598. if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) == TCL_OK) {
  599. if (interp->result && interp->result[0])
  600. status = NOTE_FWD;
  601. if (status == NOTE_AWAY) {
  602. /* User is away in all sessions -- just notify the user that a
  603. * message arrived and was stored. (only oldest session is notified.)
  604. */
  605. dprintf(iaway, "*** %s.\n", BOT_NOTEARRIVED);
  606. }
  607. return status;
  608. }
  609. return NOTE_ERROR;
  610. }