botcmd.c 32 KB

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