botcmd.c 33 KB

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