botcmd.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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->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. for (i = 0; i < dcc_total; i++) {
  367. if (dcc[i].type == &DCC_BOT) {
  368. if (!ok) {
  369. ok = 1;
  370. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s:", BOT_BOTSCONNECTED);
  371. }
  372. sprintf(s, " %s%c%-15s %s",
  373. dcc[i].status & STAT_CALLED ? "<-" : "->",
  374. dcc[i].status & STAT_SHARE ? '+' : ' ',
  375. dcc[i].nick, dcc[i].u.bot->version);
  376. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s", s);
  377. }
  378. }
  379. ok = 0;
  380. for (i = 0; i < dcc_total; i++) {
  381. if (dcc[i].type->flags & DCT_REMOTEWHO) {
  382. if (dcc[i].u.chat->channel != chan) {
  383. if (!ok) {
  384. ok = 1;
  385. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s:", BOT_OTHERPEOPLE);
  386. }
  387. l = sprintf(s, " %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick, dcc[i].host);
  388. if (now - dcc[i].timeval > 300) {
  389. k = (now - dcc[i].timeval) / 60;
  390. if (k < 60)
  391. sprintf(s + l, " (%s %dm)", MISC_IDLE, k);
  392. else
  393. sprintf(s + l, " (%s %dh%dm)", MISC_IDLE, k / 60, k % 60);
  394. }
  395. botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s", s);
  396. if (dcc[i].u.chat->away != NULL)
  397. botnet_send_priv(idx, conf.bot->nick, nick, NULL, " %s: %s", MISC_AWAY, dcc[i].u.chat->away);
  398. }
  399. }
  400. }
  401. }
  402. static void bot_shellinfo(int idx, char *par)
  403. {
  404. char *username = NULL, *sysname = NULL, *nodename = NULL;
  405. username = newsplit(&par);
  406. sysname = newsplit(&par);
  407. nodename = newsplit(&par);
  408. set_user(&USERENTRY_USERNAME, dcc[idx].user, username);
  409. set_user(&USERENTRY_OS, dcc[idx].user, sysname);
  410. dcc[idx].u.bot->sysname[0] = 0;
  411. strcpy(dcc[idx].u.bot->sysname, sysname);
  412. set_user(&USERENTRY_NODENAME, dcc[idx].user, nodename);
  413. }
  414. /* who <from@bot> <tobot> <chan#>
  415. */
  416. static void bot_who(int idx, char *par)
  417. {
  418. char *from = NULL, *to = NULL, *p = NULL;
  419. int i, chan;
  420. from = newsplit(&par);
  421. p = strchr(from, '@');
  422. if (!p) {
  423. sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
  424. from = TBUF;
  425. }
  426. to = newsplit(&par);
  427. if (!egg_strcasecmp(to, conf.bot->nick))
  428. to[0] = 0; /* (for me) */
  429. chan = base64_to_int(par);
  430. if (to[0]) { /* Pass it on */
  431. i = nextbot(to);
  432. if (i >= 0)
  433. botnet_send_who(i, from, to, chan);
  434. } else {
  435. remote_tell_who(idx, from, chan);
  436. }
  437. }
  438. static void bot_endlink(int idx, char *par)
  439. {
  440. dcc[idx].status &= ~STAT_LINKING;
  441. }
  442. static void bot_ping(int idx, char *par)
  443. {
  444. botnet_send_pong(idx);
  445. }
  446. static void bot_pong(int idx, char *par)
  447. {
  448. dcc[idx].status &= ~STAT_PINGED;
  449. if (dcc[idx].pingtime > (now - 120))
  450. dcc[idx].pingtime -= now;
  451. else
  452. dcc[idx].pingtime = 120;
  453. }
  454. /* link <from@bot> <who> <to-whom>
  455. */
  456. static void bot_link(int idx, char *par)
  457. {
  458. char *from = NULL, *bot = NULL, *rfrom = NULL;
  459. int i;
  460. from = newsplit(&par);
  461. bot = newsplit(&par);
  462. if (!egg_strcasecmp(bot, conf.bot->nick)) {
  463. if ((rfrom = strchr(from, ':')))
  464. rfrom++;
  465. else
  466. rfrom = from;
  467. putlog(LOG_CMDS, "*", "#%s# link %s", rfrom, par);
  468. if (botlink(from, -1, par))
  469. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s ...", BOT_LINKATTEMPT, par);
  470. else
  471. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s.", BOT_CANTLINKTHERE);
  472. } else {
  473. i = nextbot(bot);
  474. if (i >= 0)
  475. botnet_send_link(i, from, bot, par);
  476. }
  477. }
  478. /* unlink <from@bot> <linking-bot> <undesired-bot> <reason>
  479. */
  480. static void bot_unlink(int idx, char *par)
  481. {
  482. char *from = NULL, *bot = NULL, *rfrom = NULL, *p = NULL, *undes = NULL;
  483. int i;
  484. from = newsplit(&par);
  485. bot = newsplit(&par);
  486. undes = newsplit(&par);
  487. if (!egg_strcasecmp(bot, conf.bot->nick)) {
  488. if ((rfrom = strchr(from, ':')))
  489. rfrom++;
  490. else
  491. rfrom = from;
  492. putlog(LOG_CMDS, "*", "#%s# unlink %s (%s)", rfrom, undes, par[0] ? par : "No reason");
  493. i = botunlink(-3, undes, par[0] ? par : NULL);
  494. if (i == 1) {
  495. p = strchr(from, '@');
  496. if (p) {
  497. /* idx will change after unlink -- get new idx
  498. *
  499. * TODO: This has changed with the new lostdcc() behaviour. Check
  500. * if we can optimise the situation.
  501. */
  502. i = nextbot(p + 1);
  503. if (i >= 0)
  504. botnet_send_priv(i, conf.bot->nick, from, NULL, "Unlinked from %s.", undes);
  505. }
  506. } else if (i == 0) {
  507. botnet_send_unlinked(-1, undes, "");
  508. p = strchr(from, '@');
  509. if (p) {
  510. /* Ditto above, about idx */
  511. i = nextbot(p + 1);
  512. if (i >= 0)
  513. botnet_send_priv(i, conf.bot->nick, from, NULL, "%s %s.", BOT_CANTUNLINK, undes);
  514. }
  515. } else {
  516. p = strchr(from, '@');
  517. if (p) {
  518. i = nextbot(p + 1);
  519. if (i >= 0)
  520. botnet_send_priv(i, conf.bot->nick, from, NULL, "Can't remotely unlink sharebots.");
  521. }
  522. }
  523. } else {
  524. i = nextbot(bot);
  525. if (i >= 0)
  526. botnet_send_unlink(i, from, bot, undes, par);
  527. }
  528. }
  529. /* Bot next share?
  530. */
  531. static void bot_update(int idx, char *par)
  532. {
  533. char *bot = NULL, x, *vversion = NULL;
  534. int vlocalhub = 0;
  535. time_t vbuildts = 0L;
  536. bot = newsplit(&par);
  537. x = par[0];
  538. if (x)
  539. par++;
  540. newsplit(&par); /* vnum */
  541. if (par[0])
  542. vlocalhub = atoi(newsplit(&par));
  543. if (par[0])
  544. vbuildts = atol(newsplit(&par));
  545. if (par[0])
  546. vversion = newsplit(&par);
  547. if (in_chain(bot))
  548. updatebot(idx, bot, x, vlocalhub, vbuildts, vversion);
  549. }
  550. /* Newbot next share?
  551. */
  552. static void bot_nlinked(int idx, char *par)
  553. {
  554. char *newbot = NULL, *next = NULL, *p = NULL, s[1024] = "", x = 0, *vversion = NULL;
  555. int bogus = 0, i, vlocalhub = 0;
  556. time_t vbuildts = 0L;
  557. newbot = newsplit(&par);
  558. next = newsplit(&par);
  559. s[0] = 0;
  560. if (!next[0]) {
  561. putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)", dcc[idx].nick);
  562. simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick, MISC_INVALIDBOT);
  563. dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
  564. } else if ((in_chain(newbot)) || (!egg_strcasecmp(newbot, conf.bot->nick))) {
  565. /* Loop! */
  566. putlog(LOG_BOTS, "*", "%s %s (mutual: %s)", BOT_LOOPDETECT, dcc[idx].nick, newbot);
  567. simple_sprintf(s, "%s %s: disconnecting %s", MISC_LOOP, newbot, dcc[idx].nick);
  568. dprintf(idx, "error Loop (%s)\n", newbot);
  569. }
  570. if (!s[0]) {
  571. for (p = newbot; *p; p++)
  572. if ((*p < 32) || (*p == 127) || ((p - newbot) >= HANDLEN))
  573. bogus = 1;
  574. i = nextbot(next);
  575. if (i != idx)
  576. bogus = 1;
  577. }
  578. if (bogus) {
  579. putlog(LOG_BOTS, "*", "%s %s! (%s -> %s)", BOT_BOGUSLINK, dcc[idx].nick, next, newbot);
  580. simple_sprintf(s, "%s: %s %s", BOT_BOGUSLINK, dcc[idx].nick, MISC_DISCONNECTED);
  581. dprintf(idx, "error %s (%s -> %s)\n", BOT_BOGUSLINK, next, newbot);
  582. }
  583. if (s[0]) {
  584. chatout("*** %s\n", s);
  585. botnet_send_unlinked(idx, dcc[idx].nick, s);
  586. dprintf(idx, "bye %s\n", BOT_ILLEGALLINK);
  587. killsock(dcc[idx].sock);
  588. lostdcc(idx);
  589. return;
  590. }
  591. x = par[0];
  592. if (x)
  593. par++;
  594. else
  595. x = '-';
  596. if (par[0])
  597. newsplit(&par); /* vnum */
  598. if (par[0])
  599. vlocalhub = atoi(newsplit(&par));
  600. if (par[0])
  601. vbuildts = atol(newsplit(&par));
  602. if (par[0])
  603. vversion = newsplit(&par);
  604. botnet_send_nlinked(idx, newbot, next, x, vlocalhub, vbuildts, vversion);
  605. if (x == '!') {
  606. #ifdef HUB
  607. chatout("*** (%s) %s %s.\n", next, NET_LINKEDTO, newbot);
  608. #else
  609. chatout("*** %s linked to botnet.\n", newbot);
  610. #endif
  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->flags & DCT_CHAT) &&
  684. (!egg_strcasecmp(dcc[i].nick, to)) &&
  685. ((sock == (-1)) || (sock == dcc[i].sock))) {
  686. if (t) {
  687. int j=0;
  688. {
  689. register char *c=p;
  690. for (; *c != '\0'; c++) if (*c == ':') j++;
  691. }
  692. dprintf(i, "%s -> %s (%lu secs, %d hop%s)\n", BOT_TRACERESULT, p2,
  693. now - t, j, (j != 1) ? "s" : "");
  694. } else
  695. dprintf(i, "%s -> %s\n", BOT_TRACERESULT, p);
  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. #ifdef HUB
  710. send_timesync(-1);
  711. #endif /* HUB */
  712. }
  713. /* reject <from> <bot>
  714. */
  715. static void bot_reject(int idx, char *par)
  716. {
  717. char *from = NULL, *who = NULL, *destbot = NULL, *frombot = NULL;
  718. struct userrec *u = NULL;
  719. int i;
  720. from = newsplit(&par);
  721. frombot = strchr(from, '@');
  722. if (frombot)
  723. frombot++;
  724. else
  725. frombot = from;
  726. i = nextbot(frombot);
  727. if (i != idx) {
  728. fake_alert(idx, "direction", frombot);
  729. return;
  730. }
  731. who = newsplit(&par);
  732. if (!(destbot = strchr(who, '@'))) {
  733. /* Rejecting a bot */
  734. i = nextbot(who);
  735. if (i < 0) {
  736. botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s (%s)",
  737. BOT_CANTUNLINK, who, BOT_DOESNTEXIST);
  738. } else if (!egg_strcasecmp(dcc[i].nick, who)) {
  739. char s[1024] = "";
  740. /* I'm the connection to the rejected bot */
  741. putlog(LOG_BOTS, "*", "%s %s %s", from, MISC_REJECTED, dcc[i].nick);
  742. dprintf(i, "bye %s\n", par[0] ? par : MISC_REJECTED);
  743. simple_sprintf(s, "%s %s (%s: %s)",
  744. MISC_DISCONNECTED, dcc[i].nick, from,
  745. par[0] ? par : MISC_REJECTED);
  746. chatout("*** %s\n", s);
  747. botnet_send_unlinked(i, dcc[i].nick, s);
  748. killsock(dcc[i].sock);
  749. lostdcc(i);
  750. } else {
  751. if (i >= 0)
  752. botnet_send_reject(i, from, NULL, who, NULL, par);
  753. }
  754. } else { /* Rejecting user */
  755. *destbot++ = 0;
  756. if (!egg_strcasecmp(destbot, conf.bot->nick)) {
  757. /* Kick someone here! */
  758. int ok = 0;
  759. for (i = 0; (i < dcc_total) && (!ok); i++)
  760. if ((!egg_strcasecmp(who, dcc[i].nick)) && (dcc[i].type->flags & DCT_CHAT)) {
  761. u = get_user_by_handle(userlist, dcc[i].nick);
  762. if (u && ((u->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_ADMIN))) {
  763. add_note(from, conf.bot->nick, BOT_NOOWNERBOOT, -1, 0);
  764. return;
  765. }
  766. do_boot(i, from, par);
  767. ok = 1;
  768. putlog(LOG_CMDS, "*", "#%s# boot %s (%s)", from, who, par[0] ? par : "No reason");
  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. #ifdef HUB
  802. char *par = NULL, *parp;
  803. par = parp = strdup(msg);
  804. if (egg_isdigit(par[0])) {
  805. int type = atoi(newsplit(&par));
  806. putlog(type, "@", "(%s) %s", botnick, par);
  807. } else {
  808. putlog(LOG_ERRORS, "*", "Malformed HL line from %s: %s %s", botnick, code, par);
  809. }
  810. free(parp);
  811. #endif /* HUB */
  812. }
  813. /* Used to send a direct msg from Tcl on one bot to Tcl on another
  814. * zapf <frombot> <tobot> <code [param]>
  815. */
  816. static void bot_zapf(int idx, char *par)
  817. {
  818. char *from = NULL, *to = NULL;
  819. int i;
  820. from = newsplit(&par);
  821. to = newsplit(&par);
  822. i = nextbot(from);
  823. if (i != idx) {
  824. fake_alert(idx, "direction", from);
  825. return;
  826. }
  827. if (!egg_strcasecmp(to, conf.bot->nick)) {
  828. /* For me! */
  829. char *opcode;
  830. opcode = newsplit(&par);
  831. check_bind_bot(from, opcode, par);
  832. return;
  833. } else {
  834. i = nextbot(to);
  835. if (i >= 0)
  836. botnet_send_zapf(i, from, to, par);
  837. }
  838. }
  839. /* Used to send a global msg from Tcl on one bot to every other bot
  840. * zapf-broad <frombot> <code [param]>
  841. */
  842. static void bot_zapfbroad(int idx, char *par)
  843. {
  844. char *from = NULL, *opcode = NULL;
  845. int i;
  846. from = newsplit(&par);
  847. opcode = newsplit(&par);
  848. i = nextbot(from);
  849. if (i != idx) {
  850. fake_alert(idx, "direction", from);
  851. return;
  852. }
  853. check_bind_bot(from, opcode, par);
  854. botnet_send_zapf_broad(idx, from, opcode, par);
  855. }
  856. static void bot_error(int idx, char *par)
  857. {
  858. putlog(LOG_MISC | LOG_BOTS, "*", "%s: %s", dcc[idx].nick, par);
  859. }
  860. /* nc <bot> <sock> <newnick>
  861. */
  862. static void bot_nickchange(int idx, char *par)
  863. {
  864. char *bot = NULL, *ssock = NULL, *newnick = NULL;
  865. int sock, i;
  866. bot = newsplit(&par);
  867. i = nextbot(bot);
  868. if (i != idx) {
  869. fake_alert(idx, "direction", bot);
  870. return;
  871. }
  872. ssock = newsplit(&par);
  873. sock = base64_to_int(ssock);
  874. newnick = newsplit(&par);
  875. i = partynick(bot, sock, newnick);
  876. if (i < 0) {
  877. fake_alert(idx, "sock#", ssock);
  878. return;
  879. }
  880. chanout_but(-1, party[i].chan, "*** (%s) Nick change: %s -> %s\n",
  881. bot, newnick, party[i].nick);
  882. botnet_send_nkch_part(idx, i, newnick);
  883. }
  884. /* join <bot> <nick> <chan> <flag><sock> <from>
  885. */
  886. static void bot_join(int idx, char *par)
  887. {
  888. char *bot = NULL, *nick = NULL, *x = NULL, *y = NULL;
  889. struct userrec *u = NULL;
  890. int i, sock, chan, i2, linking = 0;
  891. bot = newsplit(&par);
  892. if (bot[0] == '!') {
  893. linking = 1;
  894. bot++;
  895. }
  896. if (b_status(idx) & STAT_LINKING) {
  897. linking = 1;
  898. }
  899. nick = newsplit(&par);
  900. x = newsplit(&par);
  901. chan = base64_to_int(x);
  902. y = newsplit(&par);
  903. if ((chan < 0) || !y[0])
  904. return; /* Woops! pre 1.2.1's send .chat off'ers
  905. * too!! */
  906. if (!y[0]) {
  907. y[0] = '-';
  908. sock = 0;
  909. } else {
  910. sock = base64_to_int(y + 1);
  911. }
  912. i = nextbot(bot);
  913. if (i != idx) { /* Ok, garbage from a 1.0g (who uses that
  914. * now?) OR raistlin being evil :) */
  915. fake_alert(idx, "direction", bot);
  916. return;
  917. }
  918. u = get_user_by_handle(userlist, nick);
  919. if (u) {
  920. sprintf(TBUF, "@%s", bot);
  921. touch_laston(u, TBUF, now);
  922. }
  923. i = addparty(bot, nick, chan, y[0], sock, par, &i2);
  924. botnet_send_join_party(idx, linking, i2);
  925. if (i != chan) {
  926. if (i >= 0) {
  927. chanout_but(-1, i, "*** (%s) %s %s %s.\n", bot, nick, NET_LEFTTHE, i ? "channel" : "party line");
  928. }
  929. if (!linking)
  930. chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick, NET_JOINEDTHE, chan ? "channel" : "party line");
  931. }
  932. }
  933. /* part <bot> <nick> <sock> [etc..]
  934. */
  935. static void bot_part(int idx, char *par)
  936. {
  937. char *bot = NULL, *nick = NULL, *etc = NULL;
  938. struct userrec *u = NULL;
  939. int sock, partyidx;
  940. int silent = 0;
  941. bot = newsplit(&par);
  942. if (bot[0] == '!') {
  943. silent = 1;
  944. bot++;
  945. }
  946. nick = newsplit(&par);
  947. etc = newsplit(&par);
  948. sock = base64_to_int(etc);
  949. u = get_user_by_handle(userlist, nick);
  950. if (u) {
  951. sprintf(TBUF, "@%s", bot);
  952. touch_laston(u, TBUF, now);
  953. }
  954. if ((partyidx = getparty(bot, sock)) != -1) {
  955. if (!silent) {
  956. register int chan = party[partyidx].chan;
  957. if (par[0])
  958. chanout_but(-1, chan, "*** (%s) %s %s %s (%s).\n", bot, nick,
  959. NET_LEFTTHE,
  960. chan ? "channel" : "party line", par);
  961. else
  962. chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick,
  963. NET_LEFTTHE,
  964. chan ? "channel" : "party line");
  965. }
  966. botnet_send_part_party(idx, partyidx, par, silent);
  967. remparty(bot, sock);
  968. }
  969. }
  970. /* away <bot> <sock> <message>
  971. * null message = unaway
  972. */
  973. static void bot_away(int idx, char *par)
  974. {
  975. char *bot = NULL, *etc = NULL;
  976. int sock, partyidx, linking = 0;
  977. bot = newsplit(&par);
  978. if (bot[0] == '!') {
  979. linking = 1;
  980. bot++;
  981. }
  982. if (b_status(idx) & STAT_LINKING) {
  983. linking = 1;
  984. }
  985. etc = newsplit(&par);
  986. sock = base64_to_int(etc);
  987. check_bind_away(bot, idx, par);
  988. if (par[0]) {
  989. partystat(bot, sock, PLSTAT_AWAY, 0);
  990. partyaway(bot, sock, par);
  991. } else {
  992. partystat(bot, sock, 0, PLSTAT_AWAY);
  993. }
  994. partyidx = getparty(bot, sock);
  995. if (!linking) {
  996. if (par[0])
  997. chanout_but(-1, party[partyidx].chan,
  998. "*** (%s) %s %s: %s.\n", bot,
  999. party[partyidx].nick, NET_AWAY, par);
  1000. else
  1001. chanout_but(-1, party[partyidx].chan,
  1002. "*** (%s) %s %s.\n", bot,
  1003. party[partyidx].nick, NET_UNAWAY);
  1004. }
  1005. botnet_send_away(idx, bot, sock, par, linking);
  1006. }
  1007. /* (a courtesy info to help during connect bursts)
  1008. * idle <bot> <sock> <#secs> [away msg]
  1009. */
  1010. static void bot_idle(int idx, char *par)
  1011. {
  1012. char *bot = NULL, *work = NULL;
  1013. int sock, idle;
  1014. bot = newsplit(&par);
  1015. work = newsplit(&par);
  1016. sock = base64_to_int(work);
  1017. work = newsplit(&par);
  1018. idle = base64_to_int(work);
  1019. partysetidle(bot, sock, idle);
  1020. if (par[0]) {
  1021. partystat(bot, sock, PLSTAT_AWAY, 0);
  1022. partyaway(bot, sock, par);
  1023. }
  1024. botnet_send_idle(idx, bot, sock, idle, par);
  1025. }
  1026. void bot_share(int idx, char *par)
  1027. {
  1028. sharein(idx, par);
  1029. }
  1030. void bot_shareupdate(int idx, char *par)
  1031. {
  1032. updatein(idx, par);
  1033. }
  1034. /* v <frombot> <tobot> <idx:nick>
  1035. */
  1036. static void bot_versions(int sock, char *par)
  1037. {
  1038. char *frombot = newsplit(&par), *tobot = NULL, *from = NULL;
  1039. if (nextbot(frombot) != sock)
  1040. fake_alert(sock, "versions-direction", frombot);
  1041. else if (egg_strcasecmp(tobot = newsplit(&par), conf.bot->nick)) {
  1042. if ((sock = nextbot(tobot)) >= 0)
  1043. dprintf(sock, "v %s %s %s\n", frombot, tobot, par);
  1044. } else {
  1045. from = newsplit(&par);
  1046. botnet_send_priv(sock, conf.bot->nick, from, frombot, "Modules loaded:\n");
  1047. /* wtf?
  1048. for (me = module_list; me; me = me->next)
  1049. botnet_send_priv(sock, conf.bot->nick, from, frombot, " Module: %s\n", me->name);
  1050. */
  1051. botnet_send_priv(sock, conf.bot->nick, from, frombot, "End of module list.\n");
  1052. }
  1053. }
  1054. /* BOT COMMANDS
  1055. *
  1056. * function call should be:
  1057. * int bot_whatever(idx,"parameters");
  1058. *
  1059. * SORT these, dcc_bot uses a shortcut which requires them sorted
  1060. *
  1061. * yup, those are tokens there to allow a more efficient botnet as
  1062. * time goes on (death to slowly upgrading llama's)
  1063. */
  1064. botcmd_t C_bot[] =
  1065. {
  1066. {"a", bot_actchan},
  1067. {"aw", bot_away},
  1068. {"bye", bot_bye},
  1069. {"c", bot_chan2},
  1070. {"cg", bot_config},
  1071. {"cgb", bot_configbroad},
  1072. {"cp", bot_cmdpass},
  1073. {"ct", bot_chat},
  1074. {"e", bot_error},
  1075. {"el", bot_endlink},
  1076. {"i", bot_idle},
  1077. {"j", bot_join},
  1078. {"l", bot_link},
  1079. {"n", bot_nlinked},
  1080. {"nc", bot_nickchange},
  1081. {"p", bot_priv},
  1082. {"pi", bot_ping},
  1083. {"po", bot_pong},
  1084. {"pt", bot_part},
  1085. {"r", bot_reject},
  1086. {"rc", bot_remotecmd},
  1087. {"rr", bot_remotereply},
  1088. {"s", bot_share},
  1089. {"sb", bot_shareupdate},
  1090. {"si", bot_shellinfo},
  1091. {"t", bot_trace},
  1092. {"tb", bot_thisbot},
  1093. {"td", bot_traced},
  1094. {"ts", bot_timesync},
  1095. {"u", bot_update},
  1096. {"ul", bot_unlink},
  1097. {"un", bot_unlinked},
  1098. {"v", bot_versions},
  1099. {"w", bot_who},
  1100. {"z", bot_zapf},
  1101. {"zb", bot_zapfbroad},
  1102. {NULL, NULL}
  1103. };
  1104. void send_remote_simul(int idx, char *bot, char *cmd, char *par)
  1105. {
  1106. char msg[SGRAB - 110] = "";
  1107. egg_snprintf(msg, sizeof msg, "r-s %d %s %d %s %lu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags,
  1108. dcc[idx].u.chat->con_chan, dcc[idx].status, cmd, par);
  1109. putbot(bot, msg);
  1110. }
  1111. /* idx nick conmask cmd par */
  1112. static void bot_rsim(char *botnick, char *code, char *msg)
  1113. {
  1114. int ridx = -1, idx = -1, i = 0, rconmask;
  1115. unsigned long status = 0;
  1116. char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX] = "", *par = NULL, *parp = NULL;
  1117. par = parp = strdup(msg);
  1118. ridx = atoi(newsplit(&par));
  1119. nick = newsplit(&par);
  1120. rconmask = atoi(newsplit(&par));
  1121. rconchan = newsplit(&par);
  1122. if (egg_isdigit(par[0]))
  1123. status = (unsigned long) atoi(newsplit(&par));
  1124. cmd = newsplit(&par);
  1125. if (ridx < 0 || !nick || !cmd) {
  1126. free(parp);
  1127. return;
  1128. }
  1129. for (i = 0; i < dcc_total; i++) {
  1130. if (dcc[i].simul == ridx) {
  1131. putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
  1132. dcc[i].simultime = now;
  1133. idx = i;
  1134. break;
  1135. }
  1136. }
  1137. if (idx < 0) {
  1138. idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
  1139. putlog(LOG_DEBUG, "*", "Making new idx for %s@%s: %d ridx: %d", nick, botnick, idx, ridx);
  1140. dcc[idx].sock = -1;
  1141. dcc[idx].timeval = now;
  1142. dcc[idx].simultime = now;
  1143. dcc[idx].simul = ridx;
  1144. dcc[idx].status = status;
  1145. strcpy(dcc[idx].simulbot, botnick);
  1146. dcc[idx].u.chat->con_flags = rconmask;
  1147. strcpy(dcc[idx].u.chat->con_chan, rconchan);
  1148. dcc[idx].u.chat->strip_flags = STRIP_ALL;
  1149. strcpy(dcc[idx].nick, nick);
  1150. egg_snprintf(buf, sizeof buf, "%s@%s", nick, botnick);
  1151. strcpy(dcc[idx].host, buf);
  1152. dcc[idx].addr = 0L;
  1153. dcc[idx].user = get_user_by_handle(userlist, nick);
  1154. }
  1155. rmspace(par);
  1156. check_bind_dcc(cmd, idx, par);
  1157. free(parp);
  1158. }
  1159. void bounce_simul(int idx, char *buf)
  1160. {
  1161. char rmsg[SGRAB - 110] = "";
  1162. if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0)
  1163. return;
  1164. egg_snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].simul, buf); /* remote-simul[r]eturn idx buf */
  1165. putbot(dcc[idx].simulbot, rmsg);
  1166. }
  1167. #ifdef HUB
  1168. static void bot_rsimr(char *botnick, char *code, char *msg)
  1169. {
  1170. if (msg[0]) {
  1171. char * par = strdup(msg), *parp = par, *prefix = NULL;
  1172. int idx = atoi(newsplit(&par));
  1173. size_t size = strlen(botnick) + 4;
  1174. prefix = (char *) calloc(1, size);
  1175. egg_snprintf(prefix, size, "[%s] ", botnick);
  1176. dumplots(idx, prefix, par);
  1177. free(prefix);
  1178. free(parp);
  1179. }
  1180. }
  1181. #endif /* HUB */
  1182. static cmd_t my_bot[] =
  1183. {
  1184. {"hl", "", (Function) bot_hublog, NULL},
  1185. #ifdef HUB /* This will only allow hubs to read the return text */
  1186. {"r-sr", "", (Function) bot_rsimr, NULL},
  1187. #endif /* HUB */
  1188. {"r-s", "", (Function) bot_rsim, NULL},
  1189. {NULL, NULL, NULL, NULL}
  1190. };
  1191. void init_botcmd()
  1192. {
  1193. add_builtins("bot", my_bot);
  1194. }