botcmd.c 36 KB

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