botcmd.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * botcmd.c -- handles:
  3. * commands that comes across the botnet
  4. * userfile transfer and update commands from sharebots
  5. *
  6. */
  7. #include "common.h"
  8. #include "botcmd.h"
  9. #include "main.h"
  10. #include "base64.h"
  11. #include "src/mod/share.mod/share.h"
  12. #include "src/mod/update.mod/update.h"
  13. #include "net.h"
  14. #include "tclhash.h"
  15. #include "misc.h"
  16. #include "dcc.h"
  17. #include "userrec.h"
  18. #include "cfg.h"
  19. #include "dccutil.h"
  20. #include "cmds.h"
  21. #include "chanprog.h"
  22. #include "botmsg.h"
  23. #include "botnet.h"
  24. #include "tandem.h"
  25. #include "users.h"
  26. #include "chan.h"
  27. #include "core_binds.h"
  28. static char TBUF[1024] = ""; /* Static buffer for goofy bot stuff */
  29. static void fake_alert(int idx, char *item, char *extra)
  30. {
  31. static time_t lastfake; /* The last time fake_alert was used */
  32. if ((now - lastfake) > 10) {
  33. /* Don't fake_alert more than once every 10secs */
  34. dprintf(idx, "ct %s NOTICE: %s (%s != %s).\n", conf.bot->nick, NET_FAKEREJECT, item, extra);
  35. putlog(LOG_BOTS, "*", "%s %s (%s != %s).", dcc[idx].nick, NET_FAKEREJECT, item, extra);
  36. lastfake = now;
  37. }
  38. }
  39. /* chan <from> <chan> <text>
  40. */
  41. static void bot_chan2(int idx, char *msg)
  42. {
  43. char *from = NULL, *p = NULL;
  44. int i, chan;
  45. from = newsplit(&msg);
  46. p = newsplit(&msg);
  47. chan = base64_to_int(p);
  48. /* Strip annoying control chars */
  49. for (p = from; *p;) {
  50. if ((*p < 32) || (*p == 127))
  51. /* FIXME: overlap strcpy(p, p + 1); */
  52. simple_sprintf(p, "%s", p + 1);
  53. else
  54. p++;
  55. }
  56. p = strchr(from, '@');
  57. if (p) {
  58. simple_sprintf(TBUF, "<%s> %s", from, msg);
  59. *p = 0;
  60. if (!partyidle(p + 1, from)) {
  61. *p = '@';
  62. fake_alert(idx, "user", from);
  63. return;
  64. }
  65. *p = '@';
  66. p++;
  67. } else {
  68. simple_sprintf(TBUF, "*** (%s) %s", from, msg);
  69. p = from;
  70. }
  71. i = nextbot(p);
  72. if (i != idx) {
  73. fake_alert(idx, "direction", p);
  74. } else {
  75. chanout_but(-1, chan, "%s\n", TBUF);
  76. /* Send to new version bots */
  77. if (i >= 0)
  78. botnet_send_chan(idx, from, NULL, chan, msg);
  79. /* if (strchr(from, '@') != NULL)
  80. check_bind_chat(from, chan, msg);
  81. else
  82. check_bind_bcst(from, chan, msg);
  83. */
  84. }
  85. }
  86. void bot_cmdpass(int idx, char *par)
  87. {
  88. char *p = strchr(par, ' ');
  89. if (p) {
  90. *p++ = 0;
  91. botnet_send_cmdpass(idx, par, p);
  92. p--;
  93. *p = ' ';
  94. } else {
  95. botnet_send_cmdpass(idx, par, "");
  96. }
  97. set_cmd_pass(par, 0);
  98. }
  99. void bot_config(int idx, char *par)
  100. {
  101. got_config_share(idx, par, 0);
  102. }
  103. void bot_configbroad(int idx, char *par)
  104. {
  105. got_config_share(idx, par, 1);
  106. }
  107. void bot_remotecmd(int idx, char *par) {
  108. char *tbot = NULL, *fbot = NULL, *fhnd = NULL, *fidx = NULL;
  109. if (par[0])
  110. tbot = newsplit(&par);
  111. if (par[0])
  112. fbot = newsplit(&par);
  113. if (par[0])
  114. fhnd = newsplit(&par);
  115. if (par[0])
  116. fidx = newsplit(&par);
  117. if (!strcmp(tbot, conf.bot->nick)) {
  118. gotremotecmd(tbot, fbot, fhnd, fidx, par);
  119. } else if (!strcmp(tbot, "*")) {
  120. botnet_send_cmd_broad(idx, fbot, fhnd, atoi(fidx), par);
  121. gotremotecmd(tbot, fbot, fhnd, fidx, par);
  122. } else {
  123. if (nextbot(tbot) != idx)
  124. botnet_send_cmd(fbot, tbot, fhnd, atoi(fidx), par);
  125. }
  126. }
  127. void bot_remotereply(int idx, char *par) {
  128. char *tbot = NULL, *fbot = NULL, *fhnd = NULL, *fidx = NULL;
  129. if (par[0])
  130. tbot = newsplit(&par);
  131. if (par[0])
  132. fbot = newsplit(&par);
  133. if (par[0])
  134. fhnd = newsplit(&par);
  135. if (par[0])
  136. fidx = newsplit(&par);
  137. if (!strcmp(tbot, conf.bot->nick)) {
  138. gotremotereply(fbot, fhnd, fidx, par);
  139. } else {
  140. if (nextbot(tbot)!= idx)
  141. botnet_send_cmdreply(fbot, tbot, fhnd, fidx, par);
  142. }
  143. }
  144. /* chat <from> <notice> -- only from bots
  145. */
  146. static void bot_chat(int idx, char *par)
  147. {
  148. char *from = NULL;
  149. int i;
  150. from = newsplit(&par);
  151. if (strchr(from, '@') != NULL) {
  152. fake_alert(idx, "bot", from);
  153. return;
  154. }
  155. /* Make sure the bot is valid */
  156. i = nextbot(from);
  157. if (i != idx) {
  158. fake_alert(idx, "direction", from);
  159. return;
  160. }
  161. chatout("*** (%s) %s\n", from, par);
  162. botnet_send_chat(idx, from, par);
  163. }
  164. /* actchan <from> <chan> <text>
  165. */
  166. static void bot_actchan(int idx, char *par)
  167. {
  168. char *from = NULL, *p = NULL;
  169. int i, chan;
  170. from = newsplit(&par);
  171. p = strchr(from, '@');
  172. if (p == NULL) {
  173. /* How can a bot do an action? */
  174. fake_alert(idx, "user@bot", from);
  175. return;
  176. }
  177. *p = 0;
  178. if (!partyidle(p + 1, from)) {
  179. *p = '@';
  180. fake_alert(idx, "user", from);
  181. return;
  182. }
  183. *p = '@';
  184. p++;
  185. i = nextbot(p);
  186. if (i != idx) {
  187. fake_alert(idx, "direction", p);
  188. return;
  189. }
  190. p = newsplit(&par);
  191. chan = base64_to_int(p);
  192. for (p = from; *p;) {
  193. if ((*p < 32) || (*p == 127))
  194. simple_sprintf(p, "%s", p + 1);
  195. /* FIXME: overlap strcpy(p, p + 1); */
  196. else
  197. p++;
  198. }
  199. chanout_but(-1, chan, "* %s %s\n", from, par);
  200. botnet_send_act(idx, from, NULL, chan, par);
  201. }
  202. /* priv <from> <to> <message>
  203. */
  204. static void bot_priv(int idx, char *par)
  205. {
  206. char *from = NULL, *p = NULL, *to = TBUF, *tobot = NULL;
  207. int i;
  208. from = newsplit(&par);
  209. tobot = newsplit(&par);
  210. splitc(to, tobot, '@');
  211. p = strchr(from, '@');
  212. if (p != NULL)
  213. p++;
  214. else
  215. p = from;
  216. i = nextbot(p);
  217. if (i != idx) {
  218. fake_alert(idx, "direction", p);
  219. return;
  220. }
  221. if (!to[0])
  222. return; /* Silently ignore notes to '@bot' this
  223. * is legacy code */
  224. if (!egg_strcasecmp(tobot, conf.bot->nick)) { /* For me! */
  225. if (p == from)
  226. add_note(to, from, par, -2, 0);
  227. else {
  228. i = add_note(to, from, par, -1, 0);
  229. if (from[0] != '@')
  230. switch (i) {
  231. case NOTE_ERROR:
  232. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s.", BOT_NOSUCHUSER, to);
  233. break;
  234. case NOTE_STORED:
  235. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s", BOT_NOTESTORED2);
  236. break;
  237. case NOTE_FULL:
  238. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s", BOT_NOTEBOXFULL);
  239. break;
  240. case NOTE_AWAY:
  241. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s", to, BOT_NOTEISAWAY);
  242. break;
  243. case NOTE_FWD:
  244. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s", "Not online; note forwarded to:", to);
  245. break;
  246. case NOTE_TCL:
  247. break; /* Do nothing */
  248. case NOTE_OK:
  249. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s.", BOT_NOTESENTTO, to);
  250. break;
  251. }
  252. }
  253. } else { /* Pass it on */
  254. i = nextbot(tobot);
  255. if (i >= 0)
  256. botnet_send_priv(i, from, to, tobot, "%s", par);
  257. }
  258. }
  259. static void bot_bye(int idx, char *par)
  260. {
  261. char s[1024] = "";
  262. int users, bots;
  263. bots = bots_in_subtree(findbot(dcc[idx].nick));
  264. users = users_in_subtree(findbot(dcc[idx].nick));
  265. simple_sprintf(s, "%s %s. %s (lost %d bot%s and %d user%s)",
  266. BOT_DISCONNECTED, dcc[idx].nick, par[0] ?
  267. par : "No reason", bots, (bots != 1) ?
  268. "s" : "", users, (users != 1) ? "s" : "");
  269. putlog(LOG_BOTS, "*", "%s", s);
  270. chatout("*** %s\n", s);
  271. botnet_send_unlinked(idx, dcc[idx].nick, s);
  272. dprintf(idx, "*bye\n");
  273. killsock(dcc[idx].sock);
  274. lostdcc(idx);
  275. }
  276. static void remote_tell_who(int idx, char *nick, int chan)
  277. {
  278. int i = 10, k, l, ok = 0;
  279. char s[1024] = "", *realnick = NULL;
  280. struct chanset_t *c = NULL;
  281. realnick = strchr(nick, ':');
  282. if (realnick)
  283. realnick++;
  284. else
  285. realnick = nick;
  286. putlog(LOG_BOTS, "*", "#%s# who", realnick);
  287. strcpy(s, "Channels: ");
  288. for (c = chanset; c; c = c->next)
  289. if (!channel_secret(c) && shouldjoin(c)) {
  290. l = strlen(c->dname);
  291. if (i + l < 1021) {
  292. if (i > 10) {
  293. simple_sprintf(s, "%s, %s", s, c->dname);
  294. } else {
  295. strcpy(s, c->dname);
  296. i += (l + 2);
  297. }
  298. }
  299. }
  300. if (i > 10) {
  301. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s (%s)", s, ver);
  302. } else {
  303. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s (%s)", BOT_NOCHANNELS, ver);
  304. }
  305. if (admin[0])
  306. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "Admin: %s", admin);
  307. if (chan == 0) {
  308. botnet_send_priv(idx, conf.bot->nick, nick, NULL,
  309. "%s (* = %s, + = %s, @ = %s)",
  310. BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
  311. } else {
  312. botnet_send_priv(idx, conf.bot->nick, nick, NULL,
  313. "%s %s%d: (* = %s, + = %s, @ = %s)\n",
  314. BOT_PEOPLEONCHAN,
  315. (chan < GLOBAL_CHANS) ? "" : "*",
  316. chan % GLOBAL_CHANS,
  317. MISC_OWNER, MISC_MASTER, MISC_OP);
  318. }
  319. for (i = 0; i < dcc_total; i++) {
  320. if (dcc[i].type && dcc[i].type->flags & DCT_REMOTEWHO) {
  321. if (dcc[i].u.chat->channel == chan) {
  322. k = sprintf(s, " %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)),
  323. dcc[i].nick, dcc[i].host);
  324. if (now - dcc[i].timeval > 300) {
  325. unsigned long mydays, hrs, mins;
  326. mydays = (now - dcc[i].timeval) / 86400;
  327. hrs = ((now - dcc[i].timeval) - (mydays * 86400)) / 3600;
  328. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  329. if (mydays > 0)
  330. sprintf(s + k, " (%s %lud%luh)", MISC_IDLE, mydays, hrs);
  331. else if (hrs > 0)
  332. sprintf(s + k, " (%s %luh%lum)", MISC_IDLE, hrs, mins);
  333. else
  334. sprintf(s + k, " (%s %lum)", MISC_IDLE, mins);
  335. }
  336. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s", s);
  337. if (dcc[i].u.chat->away != NULL)
  338. botnet_send_priv(idx, conf.bot->nick, nick, NULL, " %s: %s", MISC_AWAY, dcc[i].u.chat->away);
  339. }
  340. }
  341. }
  342. for (i = 0; i < dcc_total; i++) {
  343. if (dcc[i].type && dcc[i].type == &DCC_BOT) {
  344. if (!ok) {
  345. ok = 1;
  346. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s:", BOT_BOTSCONNECTED);
  347. }
  348. sprintf(s, " %s%c%-15s %s",
  349. dcc[i].status & STAT_CALLED ? "<-" : "->",
  350. dcc[i].status & STAT_SHARE ? '+' : ' ',
  351. dcc[i].nick, dcc[i].u.bot->version);
  352. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s", s);
  353. }
  354. }
  355. ok = 0;
  356. for (i = 0; i < dcc_total; i++) {
  357. if (dcc[i].type && dcc[i].type->flags & DCT_REMOTEWHO) {
  358. if (dcc[i].u.chat->channel != chan) {
  359. if (!ok) {
  360. ok = 1;
  361. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s:", BOT_OTHERPEOPLE);
  362. }
  363. l = sprintf(s, " %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick, dcc[i].host);
  364. if (now - dcc[i].timeval > 300) {
  365. k = (now - dcc[i].timeval) / 60;
  366. if (k < 60)
  367. sprintf(s + l, " (%s %dm)", MISC_IDLE, k);
  368. else
  369. sprintf(s + l, " (%s %dh%dm)", MISC_IDLE, k / 60, k % 60);
  370. }
  371. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s", s);
  372. if (dcc[i].u.chat->away != NULL)
  373. botnet_send_priv(idx, conf.bot->nick, nick, NULL, " %s: %s", MISC_AWAY, dcc[i].u.chat->away);
  374. }
  375. }
  376. }
  377. }
  378. static void bot_shellinfo(int idx, char *par)
  379. {
  380. char *username = NULL, *sysname = NULL, *nodename = NULL;
  381. username = newsplit(&par);
  382. sysname = newsplit(&par);
  383. nodename = newsplit(&par);
  384. set_user(&USERENTRY_USERNAME, dcc[idx].user, username);
  385. set_user(&USERENTRY_OS, dcc[idx].user, sysname);
  386. dcc[idx].u.bot->sysname[0] = 0;
  387. strcpy(dcc[idx].u.bot->sysname, sysname);
  388. set_user(&USERENTRY_NODENAME, dcc[idx].user, nodename);
  389. }
  390. /* who <from@bot> <tobot> <chan#>
  391. */
  392. static void bot_who(int idx, char *par)
  393. {
  394. char *from = NULL, *to = NULL, *p = NULL;
  395. int i, chan;
  396. from = newsplit(&par);
  397. p = strchr(from, '@');
  398. if (!p) {
  399. simple_sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
  400. from = TBUF;
  401. }
  402. to = newsplit(&par);
  403. if (!egg_strcasecmp(to, conf.bot->nick))
  404. to[0] = 0; /* (for me) */
  405. chan = base64_to_int(par);
  406. if (to[0]) { /* Pass it on */
  407. i = nextbot(to);
  408. if (i >= 0)
  409. botnet_send_who(i, from, to, chan);
  410. } else {
  411. remote_tell_who(idx, from, chan);
  412. }
  413. }
  414. static void bot_endlink(int idx, char *par)
  415. {
  416. dcc[idx].status &= ~STAT_LINKING;
  417. }
  418. static void bot_ping(int idx, char *par)
  419. {
  420. botnet_send_pong(idx);
  421. }
  422. static void bot_pong(int idx, char *par)
  423. {
  424. dcc[idx].status &= ~STAT_PINGED;
  425. if (dcc[idx].pingtime > (now - 120))
  426. dcc[idx].pingtime -= now;
  427. else
  428. dcc[idx].pingtime = 120;
  429. }
  430. /* link <from@bot> <who> <to-whom>
  431. */
  432. static void bot_link(int idx, char *par)
  433. {
  434. char *from = NULL, *bot = NULL, *rfrom = NULL;
  435. int i;
  436. from = newsplit(&par);
  437. bot = newsplit(&par);
  438. if (!egg_strcasecmp(bot, conf.bot->nick)) {
  439. if ((rfrom = strchr(from, ':')))
  440. rfrom++;
  441. else
  442. rfrom = from;
  443. putlog(LOG_CMDS, "*", "#%s# link %s", rfrom, par);
  444. if (botlink(from, -1, par))
  445. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s ...", BOT_LINKATTEMPT, par);
  446. else
  447. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s.", BOT_CANTLINKTHERE);
  448. } else {
  449. i = nextbot(bot);
  450. if (i >= 0)
  451. botnet_send_link(i, from, bot, par);
  452. }
  453. }
  454. /* unlink <from@bot> <linking-bot> <undesired-bot> <reason>
  455. */
  456. static void bot_unlink(int idx, char *par)
  457. {
  458. char *from = NULL, *bot = NULL, *rfrom = NULL, *p = NULL, *undes = NULL;
  459. int i;
  460. from = newsplit(&par);
  461. bot = newsplit(&par);
  462. undes = newsplit(&par);
  463. if (!egg_strcasecmp(bot, conf.bot->nick)) {
  464. if ((rfrom = strchr(from, ':')))
  465. rfrom++;
  466. else
  467. rfrom = from;
  468. putlog(LOG_CMDS, "*", "#%s# unlink %s (%s)", rfrom, undes, par[0] ? par : "No reason");
  469. i = botunlink(-3, undes, par[0] ? par : NULL);
  470. if (i == 1) {
  471. p = strchr(from, '@');
  472. if (p) {
  473. /* idx will change after unlink -- get new idx
  474. *
  475. * TODO: This has changed with the new lostdcc() behaviour. Check
  476. * if we can optimise the situation.
  477. */
  478. i = nextbot(p + 1);
  479. if (i >= 0)
  480. botnet_send_priv(i, conf.bot->nick, from, NULL, "Unlinked from %s.", undes);
  481. }
  482. } else if (i == 0) {
  483. botnet_send_unlinked(-1, undes, "");
  484. p = strchr(from, '@');
  485. if (p) {
  486. /* Ditto above, about idx */
  487. i = nextbot(p + 1);
  488. if (i >= 0)
  489. botnet_send_priv(i, conf.bot->nick, from, NULL, "%s %s.", BOT_CANTUNLINK, undes);
  490. }
  491. } else {
  492. p = strchr(from, '@');
  493. if (p) {
  494. i = nextbot(p + 1);
  495. if (i >= 0)
  496. botnet_send_priv(i, conf.bot->nick, from, NULL, "Can't remotely unlink sharebots.");
  497. }
  498. }
  499. } else {
  500. i = nextbot(bot);
  501. if (i >= 0)
  502. botnet_send_unlink(i, from, bot, undes, par);
  503. }
  504. }
  505. /* Bot next share?
  506. */
  507. static void bot_update(int idx, char *par)
  508. {
  509. char *bot = NULL, x, *vversion = NULL;
  510. int vlocalhub = 0;
  511. time_t vbuildts = 0L;
  512. bot = newsplit(&par);
  513. x = par[0];
  514. if (x)
  515. par++;
  516. newsplit(&par); /* vnum */
  517. if (par[0])
  518. vlocalhub = atoi(newsplit(&par));
  519. if (par[0])
  520. vbuildts = atol(newsplit(&par));
  521. if (par[0])
  522. vversion = newsplit(&par);
  523. if (in_chain(bot))
  524. updatebot(idx, bot, x, vlocalhub, vbuildts, vversion);
  525. }
  526. /* Newbot next share?
  527. */
  528. static void bot_nlinked(int idx, char *par)
  529. {
  530. char *newbot = NULL, *next = NULL, *p = NULL, s[1024] = "", x = 0, *vversion = NULL;
  531. int bogus = 0, i, vlocalhub = 0;
  532. time_t vbuildts = 0L;
  533. newbot = newsplit(&par);
  534. next = newsplit(&par);
  535. s[0] = 0;
  536. if (!next[0]) {
  537. putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)", dcc[idx].nick);
  538. simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick, MISC_INVALIDBOT);
  539. dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
  540. } else if ((in_chain(newbot)) || (!egg_strcasecmp(newbot, conf.bot->nick))) {
  541. /* Loop! */
  542. putlog(LOG_BOTS, "*", "%s %s (mutual: %s)", BOT_LOOPDETECT, dcc[idx].nick, newbot);
  543. simple_sprintf(s, "%s %s: disconnecting %s", MISC_LOOP, newbot, dcc[idx].nick);
  544. dprintf(idx, "error Loop (%s)\n", newbot);
  545. }
  546. if (!s[0]) {
  547. for (p = newbot; *p; p++)
  548. if ((*p < 32) || (*p == 127) || ((p - newbot) >= HANDLEN))
  549. bogus = 1;
  550. i = nextbot(next);
  551. if (i != idx)
  552. bogus = 1;
  553. }
  554. if (bogus) {
  555. putlog(LOG_BOTS, "*", "%s %s! (%s -> %s)", BOT_BOGUSLINK, dcc[idx].nick, next, newbot);
  556. simple_sprintf(s, "%s: %s %s", BOT_BOGUSLINK, dcc[idx].nick, MISC_DISCONNECTED);
  557. dprintf(idx, "error %s (%s -> %s)\n", BOT_BOGUSLINK, next, newbot);
  558. }
  559. if (s[0]) {
  560. chatout("*** %s\n", s);
  561. botnet_send_unlinked(idx, dcc[idx].nick, s);
  562. dprintf(idx, "bye %s\n", BOT_ILLEGALLINK);
  563. killsock(dcc[idx].sock);
  564. lostdcc(idx);
  565. return;
  566. }
  567. x = par[0];
  568. if (x)
  569. par++;
  570. else
  571. x = '-';
  572. if (par[0])
  573. newsplit(&par); /* vnum */
  574. if (par[0])
  575. vlocalhub = atoi(newsplit(&par));
  576. if (par[0])
  577. vbuildts = atol(newsplit(&par));
  578. if (par[0])
  579. vversion = newsplit(&par);
  580. botnet_send_nlinked(idx, newbot, next, x, vlocalhub, vbuildts, vversion);
  581. if (x == '!') {
  582. if (conf.bot->hub)
  583. chatout("*** (%s) %s %s.\n", next, NET_LINKEDTO, newbot);
  584. else
  585. chatout("*** %s linked to botnet.\n", newbot);
  586. x = '-';
  587. }
  588. addbot(newbot, dcc[idx].nick, next, x, vlocalhub, vbuildts, vversion ? vversion : (char *) "");
  589. }
  590. static void bot_unlinked(int idx, char *par)
  591. {
  592. int i;
  593. char *bot = NULL;
  594. bot = newsplit(&par);
  595. i = nextbot(bot);
  596. if ((i >= 0) && (i != idx)) /* Bot is NOT downstream along idx, so
  597. * BOGUS! */
  598. fake_alert(idx, "direction", bot);
  599. else if (i >= 0) { /* Valid bot downstream of idx */
  600. if (par[0])
  601. /* #ifdef HUB */
  602. chatout("*** (%s) %s\n", lastbot(bot), par);
  603. /*
  604. #else
  605. chatout("*** %s unlinked from botnet.\n", par);
  606. #endif
  607. */
  608. botnet_send_unlinked(idx, bot, par);
  609. unvia(idx, findbot(bot));
  610. rembot(bot);
  611. }
  612. /* Otherwise it's not even a valid bot, so just ignore! */
  613. }
  614. /* trace <from@bot> <dest> <chain:chain..>
  615. */
  616. static void bot_trace(int idx, char *par)
  617. {
  618. char *from = NULL, *dest = NULL;
  619. int i;
  620. from = newsplit(&par);
  621. dest = newsplit(&par);
  622. simple_sprintf(TBUF, "%s:%s", par, conf.bot->nick);
  623. botnet_send_traced(idx, from, TBUF);
  624. if (egg_strcasecmp(dest, conf.bot->nick) && ((i = nextbot(dest)) > 0))
  625. botnet_send_trace(i, from, dest, par);
  626. }
  627. /* traced <to@bot> <chain:chain..>
  628. */
  629. static void bot_traced(int idx, char *par)
  630. {
  631. char *to = NULL, *p = NULL;
  632. int i, sock;
  633. to = newsplit(&par);
  634. p = strchr(to, '@');
  635. if (p == NULL)
  636. p = to;
  637. else {
  638. *p = 0;
  639. p++;
  640. }
  641. if (!egg_strcasecmp(p, conf.bot->nick)) {
  642. time_t t = 0;
  643. char *p2 = par, *ss = TBUF;
  644. splitc(ss, to, ':');
  645. if (ss[0])
  646. sock = atoi(ss);
  647. else
  648. sock = (-1);
  649. if (par[0] == ':') {
  650. t = atoi(par + 1);
  651. p2 = strchr(par + 1, ':');
  652. if (p2)
  653. p2++;
  654. else
  655. p2 = par + 1;
  656. }
  657. for (i = 0; i < dcc_total; i++) {
  658. if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && (!egg_strcasecmp(dcc[i].nick, to)) &&
  659. ((sock == (-1)) || (sock == dcc[i].sock))) {
  660. if (t) {
  661. int j=0;
  662. {
  663. register char *c=p;
  664. for (; *c != '\0'; c++) if (*c == ':') j++;
  665. }
  666. dprintf(i, "%s -> %s (%lu secs, %d hop%s)\n", BOT_TRACERESULT, p2,
  667. now - t, j, (j != 1) ? "s" : "");
  668. } else
  669. dprintf(i, "%s -> %s\n", BOT_TRACERESULT, p);
  670. }
  671. }
  672. } else {
  673. i = nextbot(p);
  674. if (p != to)
  675. *--p = '@';
  676. if (i >= 0)
  677. botnet_send_traced(i, to, par);
  678. }
  679. }
  680. static void bot_timesync(int idx, char *par)
  681. {
  682. // putlog(LOG_DEBUG, "@", "Got timesync from %s: %s (%li - %li)", dcc[idx].nick, par, atol(par), now);
  683. timesync = atol(par) - now;
  684. if (conf.bot->hub)
  685. send_timesync(-1);
  686. }
  687. /* reject <from> <bot>
  688. */
  689. static void bot_reject(int idx, char *par)
  690. {
  691. char *from = NULL, *who = NULL, *destbot = NULL, *frombot = NULL;
  692. struct userrec *u = NULL;
  693. int i;
  694. from = newsplit(&par);
  695. frombot = strchr(from, '@');
  696. if (frombot)
  697. frombot++;
  698. else
  699. frombot = from;
  700. i = nextbot(frombot);
  701. if (i != idx) {
  702. fake_alert(idx, "direction", frombot);
  703. return;
  704. }
  705. who = newsplit(&par);
  706. destbot = strchr(who, '@');
  707. *destbot++ = 0;
  708. if (!egg_strcasecmp(destbot, conf.bot->nick)) {
  709. /* Kick someone here! */
  710. int ok = 0;
  711. for (i = 0; (i < dcc_total) && (!ok); i++) {
  712. if (dcc[i].type && (!egg_strcasecmp(who, dcc[i].nick)) && (dcc[i].type->flags & DCT_CHAT)) {
  713. u = get_user_by_handle(userlist, from);
  714. if (u) {
  715. if (!whois_access(u, dcc[idx].user)) {
  716. add_note(from, conf.bot->nick, "Sorry, you cannot boot them.", -1, 0);
  717. return;
  718. }
  719. do_boot(i, from, par);
  720. ok = 1;
  721. putlog(LOG_CMDS, "*", "#%s# boot %s (%s)", from, who, par[0] ? par : "No reason");
  722. }
  723. }
  724. }
  725. } else {
  726. i = nextbot(destbot);
  727. *--destbot = '@';
  728. if (i >= 0)
  729. botnet_send_reject(i, from, NULL, who, NULL, par);
  730. }
  731. }
  732. static void bot_thisbot(int idx, char *par)
  733. {
  734. if (egg_strcasecmp(par, dcc[idx].nick)) {
  735. char s[1024] = "";
  736. putlog(LOG_BOTS, "*", NET_WRONGBOT, dcc[idx].nick, par);
  737. dprintf(idx, "bye %s\n", MISC_IMPOSTER);
  738. simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
  739. MISC_IMPOSTER);
  740. chatout("*** %s\n", s);
  741. botnet_send_unlinked(idx, dcc[idx].nick, s);
  742. unvia(idx, findbot(dcc[idx].nick));
  743. killsock(dcc[idx].sock);
  744. lostdcc(idx);
  745. return;
  746. }
  747. /* Set capitalization the way they want it */
  748. noshare = 1;
  749. change_handle(dcc[idx].user, par);
  750. noshare = 0;
  751. strcpy(dcc[idx].nick, par);
  752. }
  753. static void bot_hublog(char *botnick, char *code, char *msg)
  754. {
  755. char *par = NULL, *parp;
  756. par = parp = strdup(msg);
  757. if (egg_isdigit(par[0])) {
  758. int type = atoi(newsplit(&par));
  759. putlog(type, "@", "(%s) %s", botnick, par);
  760. } else {
  761. putlog(LOG_ERRORS, "*", "Malformed HL line from %s: %s %s", botnick, code, par);
  762. }
  763. free(parp);
  764. }
  765. /* Used to send a direct msg from Tcl on one bot to Tcl on another
  766. * zapf <frombot> <tobot> <code [param]>
  767. */
  768. static void bot_zapf(int idx, char *par)
  769. {
  770. char *from = NULL, *to = NULL;
  771. int i;
  772. from = newsplit(&par);
  773. to = newsplit(&par);
  774. i = nextbot(from);
  775. if (i != idx) {
  776. fake_alert(idx, "direction", from);
  777. return;
  778. }
  779. if (!egg_strcasecmp(to, conf.bot->nick)) {
  780. /* For me! */
  781. char *opcode;
  782. opcode = newsplit(&par);
  783. check_bind_bot(from, opcode, par);
  784. return;
  785. } else {
  786. i = nextbot(to);
  787. if (i >= 0)
  788. botnet_send_zapf(i, from, to, par);
  789. }
  790. }
  791. /* Used to send a global msg from Tcl on one bot to every other bot
  792. * zapf-broad <frombot> <code [param]>
  793. */
  794. static void bot_zapfbroad(int idx, char *par)
  795. {
  796. char *from = NULL, *opcode = NULL;
  797. int i;
  798. from = newsplit(&par);
  799. opcode = newsplit(&par);
  800. i = nextbot(from);
  801. if (i != idx) {
  802. fake_alert(idx, "direction", from);
  803. return;
  804. }
  805. check_bind_bot(from, opcode, par);
  806. botnet_send_zapf_broad(idx, from, opcode, par);
  807. }
  808. static void bot_error(int idx, char *par)
  809. {
  810. putlog(LOG_MISC | LOG_BOTS, "*", "%s: %s", dcc[idx].nick, par);
  811. }
  812. /* nc <bot> <sock> <newnick>
  813. */
  814. static void bot_nickchange(int idx, char *par)
  815. {
  816. char *bot = NULL, *ssock = NULL, *newnick = NULL;
  817. int sock, i;
  818. bot = newsplit(&par);
  819. i = nextbot(bot);
  820. if (i != idx) {
  821. fake_alert(idx, "direction", bot);
  822. return;
  823. }
  824. ssock = newsplit(&par);
  825. sock = base64_to_int(ssock);
  826. newnick = newsplit(&par);
  827. i = partynick(bot, sock, newnick);
  828. if (i < 0) {
  829. fake_alert(idx, "sock#", ssock);
  830. return;
  831. }
  832. chanout_but(-1, party[i].chan, "*** (%s) Nick change: %s -> %s\n",
  833. bot, newnick, party[i].nick);
  834. botnet_send_nkch_part(idx, i, newnick);
  835. }
  836. /* join <bot> <nick> <chan> <flag><sock> <from>
  837. */
  838. static void bot_join(int idx, char *par)
  839. {
  840. char *bot = NULL, *nick = NULL, *x = NULL, *y = NULL;
  841. struct userrec *u = NULL;
  842. int i, sock, chan, i2, linking = 0;
  843. bot = newsplit(&par);
  844. if (bot[0] == '!') {
  845. linking = 1;
  846. bot++;
  847. }
  848. if (b_status(idx) & STAT_LINKING) {
  849. linking = 1;
  850. }
  851. nick = newsplit(&par);
  852. x = newsplit(&par);
  853. chan = base64_to_int(x);
  854. y = newsplit(&par);
  855. if ((chan < 0) || !y[0])
  856. return; /* Woops! pre 1.2.1's send .chat off'ers
  857. * too!! */
  858. if (!y[0]) {
  859. y[0] = '-';
  860. sock = 0;
  861. } else {
  862. sock = base64_to_int(y + 1);
  863. }
  864. i = nextbot(bot);
  865. if (i != idx) { /* Ok, garbage from a 1.0g (who uses that
  866. * now?) OR raistlin being evil :) */
  867. fake_alert(idx, "direction", bot);
  868. return;
  869. }
  870. u = get_user_by_handle(userlist, nick);
  871. if (u) {
  872. simple_sprintf(TBUF, "@%s", bot);
  873. touch_laston(u, TBUF, now);
  874. }
  875. i = addparty(bot, nick, chan, y[0], sock, par, &i2);
  876. botnet_send_join_party(idx, linking, i2);
  877. if (i != chan) {
  878. if (i >= 0) {
  879. chanout_but(-1, i, "*** (%s) %s %s %s.\n", bot, nick, NET_LEFTTHE, i ? "channel" : "party line");
  880. }
  881. if (!linking)
  882. chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick, NET_JOINEDTHE, chan ? "channel" : "party line");
  883. }
  884. }
  885. /* part <bot> <nick> <sock> [etc..]
  886. */
  887. static void bot_part(int idx, char *par)
  888. {
  889. char *bot = NULL, *nick = NULL, *etc = NULL;
  890. struct userrec *u = NULL;
  891. int sock, partyidx;
  892. int silent = 0;
  893. bot = newsplit(&par);
  894. if (bot[0] == '!') {
  895. silent = 1;
  896. bot++;
  897. }
  898. nick = newsplit(&par);
  899. etc = newsplit(&par);
  900. sock = base64_to_int(etc);
  901. u = get_user_by_handle(userlist, nick);
  902. if (u) {
  903. simple_sprintf(TBUF, "@%s", bot);
  904. touch_laston(u, TBUF, now);
  905. }
  906. if ((partyidx = getparty(bot, sock)) != -1) {
  907. if (!silent) {
  908. register int chan = party[partyidx].chan;
  909. if (par[0])
  910. chanout_but(-1, chan, "*** (%s) %s %s %s (%s).\n", bot, nick,
  911. NET_LEFTTHE,
  912. chan ? "channel" : "party line", par);
  913. else
  914. chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick,
  915. NET_LEFTTHE,
  916. chan ? "channel" : "party line");
  917. }
  918. botnet_send_part_party(idx, partyidx, par, silent);
  919. remparty(bot, sock);
  920. }
  921. }
  922. /* away <bot> <sock> <message>
  923. * null message = unaway
  924. */
  925. static void bot_away(int idx, char *par)
  926. {
  927. char *bot = NULL, *etc = NULL;
  928. int sock, partyidx, linking = 0;
  929. bot = newsplit(&par);
  930. if (bot[0] == '!') {
  931. linking = 1;
  932. bot++;
  933. }
  934. if (b_status(idx) & STAT_LINKING) {
  935. linking = 1;
  936. }
  937. etc = newsplit(&par);
  938. sock = base64_to_int(etc);
  939. check_bind_away(bot, idx, par);
  940. if (par[0]) {
  941. partystat(bot, sock, PLSTAT_AWAY, 0);
  942. partyaway(bot, sock, par);
  943. } else {
  944. partystat(bot, sock, 0, PLSTAT_AWAY);
  945. }
  946. partyidx = getparty(bot, sock);
  947. if (!linking) {
  948. if (par[0])
  949. chanout_but(-1, party[partyidx].chan,
  950. "*** (%s) %s %s: %s.\n", bot,
  951. party[partyidx].nick, NET_AWAY, par);
  952. else
  953. chanout_but(-1, party[partyidx].chan,
  954. "*** (%s) %s %s.\n", bot,
  955. party[partyidx].nick, NET_UNAWAY);
  956. }
  957. botnet_send_away(idx, bot, sock, par, linking);
  958. }
  959. /* (a courtesy info to help during connect bursts)
  960. * idle <bot> <sock> <#secs> [away msg]
  961. */
  962. static void bot_idle(int idx, char *par)
  963. {
  964. char *bot = NULL, *work = NULL;
  965. int sock, idle;
  966. bot = newsplit(&par);
  967. work = newsplit(&par);
  968. sock = base64_to_int(work);
  969. work = newsplit(&par);
  970. idle = base64_to_int(work);
  971. partysetidle(bot, sock, idle);
  972. if (par[0]) {
  973. partystat(bot, sock, PLSTAT_AWAY, 0);
  974. partyaway(bot, sock, par);
  975. }
  976. botnet_send_idle(idx, bot, sock, idle, par);
  977. }
  978. void bot_share(int idx, char *par)
  979. {
  980. sharein(idx, par);
  981. }
  982. void bot_shareupdate(int idx, char *par)
  983. {
  984. updatein(idx, par);
  985. }
  986. /* v <frombot> <tobot> <idx:nick>
  987. */
  988. static void bot_versions(int sock, char *par)
  989. {
  990. char *frombot = newsplit(&par), *tobot = NULL, *from = NULL;
  991. if (nextbot(frombot) != sock)
  992. fake_alert(sock, "versions-direction", frombot);
  993. else if (egg_strcasecmp(tobot = newsplit(&par), conf.bot->nick)) {
  994. if ((sock = nextbot(tobot)) >= 0)
  995. dprintf(sock, "v %s %s %s\n", frombot, tobot, par);
  996. } else {
  997. from = newsplit(&par);
  998. botnet_send_priv(sock, conf.bot->nick, from, frombot, "Modules loaded:\n");
  999. /* wtf?
  1000. for (me = module_list; me; me = me->next)
  1001. botnet_send_priv(sock, conf.bot->nick, from, frombot, " Module: %s\n", me->name);
  1002. */
  1003. botnet_send_priv(sock, conf.bot->nick, from, frombot, "End of module list.\n");
  1004. }
  1005. }
  1006. /* BOT COMMANDS
  1007. *
  1008. * function call should be:
  1009. * int bot_whatever(idx,"parameters");
  1010. *
  1011. * SORT these, dcc_bot uses a shortcut which requires them sorted
  1012. *
  1013. * yup, those are tokens there to allow a more efficient botnet as
  1014. * time goes on (death to slowly upgrading llama's)
  1015. */
  1016. botcmd_t C_bot[] =
  1017. {
  1018. {"a", bot_actchan, 0},
  1019. {"aw", bot_away, 0},
  1020. {"bye", bot_bye, 0},
  1021. {"c", bot_chan2, 0},
  1022. {"cg", bot_config, 0},
  1023. {"cgb", bot_configbroad, 0},
  1024. {"cp", bot_cmdpass, 0},
  1025. {"ct", bot_chat, 0},
  1026. {"e", bot_error, 0},
  1027. {"el", bot_endlink, 0},
  1028. {"i", bot_idle, 0},
  1029. {"j", bot_join, 0},
  1030. {"l", bot_link, 0},
  1031. {"n", bot_nlinked, 0},
  1032. {"nc", bot_nickchange, 0},
  1033. {"p", bot_priv, 0},
  1034. {"pi", bot_ping, 0},
  1035. {"po", bot_pong, 0},
  1036. {"pt", bot_part, 0},
  1037. {"r", bot_reject, 0},
  1038. {"rc", bot_remotecmd, 0},
  1039. {"rr", bot_remotereply, 0},
  1040. {"s", bot_share, 0},
  1041. {"sb", bot_shareupdate, 0},
  1042. {"si", bot_shellinfo, 0},
  1043. {"t", bot_trace, 0},
  1044. {"tb", bot_thisbot, 0},
  1045. {"td", bot_traced, 0},
  1046. {"ts", bot_timesync, 0},
  1047. {"u", bot_update, 0},
  1048. {"ul", bot_unlink, 0},
  1049. {"un", bot_unlinked, 0},
  1050. {"v", bot_versions, 0},
  1051. {"w", bot_who, 0},
  1052. {"z", bot_zapf, 0},
  1053. {"zb", bot_zapfbroad, 0},
  1054. {NULL, NULL, 0}
  1055. };
  1056. void send_remote_simul(int idx, char *bot, char *cmd, char *par)
  1057. {
  1058. char msg[SGRAB - 110] = "";
  1059. egg_snprintf(msg, sizeof msg, "r-s %d %s %d %s %lu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags,
  1060. dcc[idx].u.chat->con_chan, dcc[idx].status, cmd, par);
  1061. putbot(bot, msg);
  1062. }
  1063. /* idx nick conmask cmd par */
  1064. static void bot_rsim(char *botnick, char *code, char *msg)
  1065. {
  1066. int ridx = -1, idx = -1, i = 0, rconmask;
  1067. unsigned long status = 0;
  1068. char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX] = "", *par = NULL, *parp = NULL;
  1069. struct userrec *u = get_user_by_handle(userlist, botnick);
  1070. if (bot_hublevel(u) == 999) {
  1071. putlog(LOG_WARN, "*", "BOTCMD received from a leaf. HIJACK.");
  1072. return;
  1073. }
  1074. par = parp = strdup(msg);
  1075. ridx = atoi(newsplit(&par));
  1076. nick = newsplit(&par);
  1077. rconmask = atoi(newsplit(&par));
  1078. rconchan = newsplit(&par);
  1079. if (egg_isdigit(par[0]))
  1080. status = (unsigned long) atoi(newsplit(&par));
  1081. cmd = newsplit(&par);
  1082. if (ridx < 0 || !nick || !cmd) {
  1083. free(parp);
  1084. return;
  1085. }
  1086. for (i = 0; i < dcc_total; i++) {
  1087. if (dcc[i].type && dcc[i].simul == ridx) {
  1088. putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
  1089. dcc[i].simultime = now;
  1090. idx = i;
  1091. break;
  1092. }
  1093. }
  1094. if (idx < 0) {
  1095. idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
  1096. putlog(LOG_DEBUG, "*", "Making new idx for %s@%s: %d ridx: %d", nick, botnick, idx, ridx);
  1097. dcc[idx].sock = -1;
  1098. dcc[idx].timeval = now;
  1099. dcc[idx].simultime = now;
  1100. dcc[idx].simul = ridx;
  1101. dcc[idx].status = status;
  1102. strcpy(dcc[idx].simulbot, botnick);
  1103. dcc[idx].u.chat->con_flags = rconmask;
  1104. strcpy(dcc[idx].u.chat->con_chan, rconchan);
  1105. dcc[idx].u.chat->strip_flags = STRIP_ALL;
  1106. strcpy(dcc[idx].nick, nick);
  1107. simple_snprintf(buf, sizeof buf, "%s@%s", nick, botnick);
  1108. strcpy(dcc[idx].host, buf);
  1109. dcc[idx].addr = 0L;
  1110. dcc[idx].user = get_user_by_handle(userlist, nick);
  1111. }
  1112. rmspace(par);
  1113. check_bind_dcc(cmd, idx, par);
  1114. free(parp);
  1115. }
  1116. void bounce_simul(int idx, char *buf)
  1117. {
  1118. char rmsg[SGRAB - 110] = "";
  1119. if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0)
  1120. return;
  1121. simple_snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].simul, buf); /* remote-simul[r]eturn idx buf */
  1122. putbot(dcc[idx].simulbot, rmsg);
  1123. }
  1124. static void bot_rsimr(char *botnick, char *code, char *msg)
  1125. {
  1126. if (msg[0]) {
  1127. char * par = strdup(msg), *parp = par, *prefix = NULL;
  1128. int idx = atoi(newsplit(&par));
  1129. size_t size = strlen(botnick) + 4;
  1130. prefix = (char *) my_calloc(1, size);
  1131. simple_snprintf(prefix, size, "[%s] ", botnick);
  1132. dumplots(idx, prefix, par);
  1133. free(prefix);
  1134. free(parp);
  1135. }
  1136. }
  1137. static cmd_t my_bot[] =
  1138. {
  1139. {"hl", "", (Function) bot_hublog, NULL, HUB},
  1140. {"r-sr", "", (Function) bot_rsimr, NULL, HUB},
  1141. {"r-s", "", (Function) bot_rsim, NULL, 0},
  1142. {NULL, NULL, NULL, NULL, 0}
  1143. };
  1144. void init_botcmd()
  1145. {
  1146. add_builtins("bot", my_bot);
  1147. }