botmsg.c 15 KB

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