1
0

botmsg.c 16 KB

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