botmsg.c 16 KB

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