botcmd.c 36 KB

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