botmsg.c 15 KB

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