botcmd.c 33 KB

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