botcmd.c 32 KB

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