botcmd.c 40 KB

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