botcmd.c 34 KB

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