botcmd.c 36 KB

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