botmsg.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 = NULL, *s = NULL;
  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) && (!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. if (tands > 0) {
  162. char *buf = NULL;
  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, conf.bot->nick)) {
  178. char tmp[24] = "";
  179. sprintf(tmp, "%i", fromidx);
  180. gotremotecmd(conf.bot->nick, conf.bot->nick, 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. egg_snprintf(buf, sizeof 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("*", conf.bot->nick, 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. egg_snprintf(buf, sizeof 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, conf.bot->nick)) {
  203. gotremotereply(conf.bot->nick, 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 (int idx, ...)
  253. {
  254. int l;
  255. char *from = NULL, *to = NULL, *tobot = NULL, *format = NULL;
  256. char tbuf[1024] = "";
  257. va_list va;
  258. va_start(va, idx);
  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, conf.bot->nick);
  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. botnet_send_zapf_broad(-1, conf.bot->nick, NULL, par);
  356. }
  357. void putbot(char *bot, char *par)
  358. {
  359. int i;
  360. char msg[SGRAB - 110] = "";
  361. if (!bot || !par || !bot[0] || !par[0])
  362. return;
  363. i = nextbot(bot);
  364. if (i < 0)
  365. return;
  366. strncpyz(msg, par, sizeof msg);
  367. botnet_send_zapf(i, conf.bot->nick, bot, msg);
  368. }
  369. void botnet_send_zapf(int idx, char *a, char *b, char *c)
  370. {
  371. int l;
  372. l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
  373. tputs(dcc[idx].sock, OBUF, l);
  374. }
  375. void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
  376. {
  377. int l;
  378. if (tands > 0) {
  379. l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
  380. send_tand_but(idx, OBUF, l);
  381. }
  382. }
  383. void botnet_send_cfg(int idx, struct cfg_entry * entry) {
  384. int l;
  385. l = simple_sprintf(OBUF, STR("cg %s %s\n"), entry->name, entry->gdata ? entry->gdata : "");
  386. tputs(dcc[idx].sock, OBUF, l);
  387. }
  388. void botnet_send_cfg_broad(int idx, struct cfg_entry * entry) {
  389. int l;
  390. if (tands > 0) {
  391. l = simple_sprintf(OBUF, STR("cg %s %s\n"), entry->name, entry->gdata ? entry->gdata : "");
  392. send_tand_but(idx, OBUF, l);
  393. }
  394. }
  395. void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
  396. {
  397. int l;
  398. if (tands > 0) {
  399. l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle, away ? away : "");
  400. send_tand_but(idx, OBUF, -l);
  401. }
  402. }
  403. void botnet_send_away(int idx, char *bot, int sock,
  404. char *msg, int linking)
  405. {
  406. int l;
  407. if (tands > 0) {
  408. l = simple_sprintf(OBUF, "aw %s%s %D %s\n",
  409. ((idx >= 0) && linking) ? "!" : "",
  410. bot, sock, msg ? msg : "");
  411. send_tand_but(idx, OBUF, -l);
  412. }
  413. }
  414. void botnet_send_join_idx(int useridx, int oldchan)
  415. {
  416. int l;
  417. if (tands > 0) {
  418. l = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
  419. conf.bot->nick, dcc[useridx].nick,
  420. dcc[useridx].u.chat->channel, geticon(useridx),
  421. dcc[useridx].sock, dcc[useridx].host);
  422. send_tand_but(-1, OBUF, -l);
  423. }
  424. }
  425. void botnet_send_join_party(int idx, int linking, int useridx, int oldchan)
  426. {
  427. int l;
  428. if (tands > 0) {
  429. l = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
  430. party[useridx].bot, party[useridx].nick,
  431. party[useridx].chan, party[useridx].flag,
  432. party[useridx].sock,
  433. party[useridx].from ? party[useridx].from : "");
  434. send_tand_but(idx, OBUF, -l);
  435. }
  436. }
  437. void botnet_send_part_idx(int useridx, char *reason)
  438. {
  439. int l = simple_sprintf(OBUF, "pt %s %s %D %s\n", conf.bot->nick,
  440. dcc[useridx].nick, dcc[useridx].sock,
  441. reason ? reason : "");
  442. if (tands > 0) {
  443. send_tand_but(-1, OBUF, -l);
  444. }
  445. }
  446. void botnet_send_part_party(int idx, int partyidx, char *reason,
  447. int silent)
  448. {
  449. int l;
  450. if (tands > 0) {
  451. l = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
  452. silent ? "!" : "", party[partyidx].bot,
  453. party[partyidx].nick, party[partyidx].sock,
  454. reason ? reason : "");
  455. send_tand_but(idx, OBUF, -l);
  456. }
  457. }
  458. void botnet_send_nkch(int useridx, char *oldnick)
  459. {
  460. int l;
  461. if (tands > 0) {
  462. l = simple_sprintf(OBUF, "nc %s %D %s\n", conf.bot->nick,
  463. dcc[useridx].sock, dcc[useridx].nick);
  464. send_tand_but(-1, OBUF, -l);
  465. }
  466. }
  467. void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
  468. {
  469. int l;
  470. if (tands > 0) {
  471. l = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot,
  472. party[useridx].sock, party[useridx].nick);
  473. send_tand_but(butidx, OBUF, -l);
  474. }
  475. }
  476. /* This part of add_note is more relevant to the botnet than
  477. * to the notes file
  478. */
  479. int add_note(char *to, char *from, char *msg, int idx, int echo)
  480. {
  481. int status, i, iaway, sock;
  482. char *p = NULL, botf[81] = "", ss[81] = "", ssf[81] = "";
  483. struct userrec *u;
  484. if (strlen(msg) > 450)
  485. msg[450] = 0; /* Notes have a limit */
  486. /* note length + PRIVMSG header + nickname + date must be <512 */
  487. p = strchr(to, '@');
  488. if (p != NULL) { /* Cross-bot note */
  489. char x[21] = "";
  490. *p = 0;
  491. strncpy(x, to, 20);
  492. x[20] = 0;
  493. *p = '@';
  494. p++;
  495. if (!egg_strcasecmp(p, conf.bot->nick)) /* To me?? */
  496. return add_note(x, from, msg, idx, echo); /* Start over, dimwit. */
  497. if (egg_strcasecmp(from, conf.bot->nick)) {
  498. if (strlen(from) > 40)
  499. from[40] = 0;
  500. if (strchr(from, '@')) {
  501. strcpy(botf, from);
  502. } else
  503. sprintf(botf, "%s@%s", from, conf.bot->nick);
  504. } else
  505. strcpy(botf, conf.bot->nick);
  506. i = nextbot(p);
  507. if (i < 0) {
  508. if (idx >= 0)
  509. dprintf(idx, BOT_NOTHERE);
  510. return NOTE_ERROR;
  511. }
  512. if ((idx >= 0) && (echo))
  513. dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
  514. if (idx >= 0) {
  515. sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
  516. botnet_send_priv(i, ssf, x, p, "%s", msg);
  517. } else
  518. botnet_send_priv(i, botf, x, p, "%s", msg);
  519. return NOTE_OK; /* Forwarded to the right bot */
  520. }
  521. /* Might be form "sock:nick" */
  522. splitc(ssf, from, ':');
  523. rmspace(ssf);
  524. splitc(ss, to, ':');
  525. rmspace(ss);
  526. if (!ss[0])
  527. sock = (-1);
  528. else
  529. sock = atoi(ss);
  530. /* Don't process if there's a note binding for it */
  531. if (idx != (-2)) { /* Notes from bots don't trigger it */
  532. if (check_bind_note(from, to, msg)) {
  533. if ((idx >= 0) && (echo))
  534. dprintf(idx, "-> %s: %s\n", to, msg);
  535. return NOTE_TCL;
  536. }
  537. }
  538. if (!(u = get_user_by_handle(userlist, to))) {
  539. if (idx >= 0)
  540. dprintf(idx, USERF_UNKNOWN);
  541. return NOTE_ERROR;
  542. }
  543. if (is_bot(u)) {
  544. if (idx >= 0)
  545. dprintf(idx, BOT_NONOTES);
  546. return NOTE_ERROR;
  547. }
  548. status = NOTE_STORED;
  549. iaway = 0;
  550. /* Online right now? */
  551. for (i = 0; i < dcc_total; i++) {
  552. if ((dcc[i].type->flags & DCT_GETNOTES) &&
  553. ((sock == (-1)) || (sock == dcc[i].sock)) &&
  554. (!egg_strcasecmp(dcc[i].nick, to))) {
  555. int aok = 1;
  556. if (dcc[i].type == &DCC_CHAT)
  557. if ((dcc[i].u.chat->away != NULL) &&
  558. (idx != (-2))) {
  559. /* Only check away if it's not from a bot */
  560. aok = 0;
  561. if (idx >= 0)
  562. dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
  563. dcc[i].u.chat->away);
  564. if (!iaway)
  565. iaway = i;
  566. status = NOTE_AWAY;
  567. }
  568. if (aok) {
  569. char *p = NULL, *fr = from;
  570. int l = 0;
  571. char work[1024] = "";
  572. while ((*msg == '<') || (*msg == '>')) {
  573. p = newsplit(&msg);
  574. if (*p == '<')
  575. l += simple_sprintf(work + l, "via %s, ", p + 1);
  576. else if (*from == '@')
  577. fr = p + 1;
  578. }
  579. if (idx == -2 || (!egg_strcasecmp(from, conf.bot->nick)))
  580. dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
  581. else
  582. dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
  583. if ((idx >= 0) && (echo))
  584. dprintf(idx, "-> %s: %s\n", to, msg);
  585. return NOTE_OK;
  586. }
  587. }
  588. }
  589. if (idx == (-2))
  590. return NOTE_OK; /* Error msg from a tandembot: don't store */
  591. status = storenote(from, to, msg, idx, NULL, 0);
  592. if (status < 0) status = NOTE_ERROR;
  593. else if (status == NOTE_AWAY) {
  594. /* User is away in all sessions -- just notify the user that a
  595. * message arrived and was stored. (only oldest session is notified.)
  596. */
  597. dprintf(iaway, "*** %s.\n", BOT_NOTEARRIVED);
  598. }
  599. return(status);
  600. }