botcmd.c 36 KB

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