botcmd.c 33 KB

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