botcmd.c 37 KB

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