botnet.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2008 Bryan Drewery
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /*
  21. * botnet.c -- handles:
  22. * keeping track of which bot's connected where in the chain
  23. * dumping a list of bots or a bot tree to a user
  24. * channel name associations on the party line
  25. * rejecting a bot
  26. * linking, unlinking, and relaying to another bot
  27. * pinging the bots periodically and checking leaf status
  28. *
  29. */
  30. #include "common.h"
  31. #include "botnet.h"
  32. #include "color.h"
  33. #include "chanprog.h"
  34. #include "net.h"
  35. #include "socket.h"
  36. #include "adns.h"
  37. #include "match.h"
  38. #include "users.h"
  39. #include "misc.h"
  40. #include "userrec.h"
  41. #include "main.h"
  42. #include "dccutil.h"
  43. #include "dcc.h"
  44. #include "botmsg.h"
  45. #include "tandem.h"
  46. #include "core_binds.h"
  47. tand_t *tandbot = NULL; /* Keep track of tandem bots on the
  48. botnet */
  49. party_t *party = NULL; /* Keep track of people on the botnet */
  50. int tands = 0; /* Number of bots on the botnet */
  51. static int maxparty = 50; /* Maximum space for party line members
  52. currently */
  53. static int parties = 0; /* Number of people on the botnet */
  54. static int share_unlinks = 1; /* Allow remote unlinks of my
  55. sharebots? */
  56. void init_party()
  57. {
  58. party = (party_t *) my_calloc(1, maxparty * sizeof(party_t));
  59. }
  60. tand_t *findbot(const char *who)
  61. {
  62. for (tand_t* ptr = tandbot; ptr; ptr = ptr->next)
  63. if (!egg_strcasecmp(ptr->bot, who))
  64. return ptr;
  65. return NULL;
  66. }
  67. /* Add a tandem bot to our chain list
  68. */
  69. void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion)
  70. {
  71. tand_t **ptr = &tandbot, *ptr2 = NULL;
  72. while (*ptr) {
  73. if (!egg_strcasecmp((*ptr)->bot, who))
  74. putlog(LOG_BOTS, "*", "!!! Duplicate botnet bot entry!!");
  75. ptr = &((*ptr)->next);
  76. }
  77. ptr2 = (tand_t *) my_calloc(1, sizeof(tand_t));
  78. strlcpy(ptr2->bot, who, HANDLEN + 1);
  79. ptr2->bot[HANDLEN] = 0;
  80. ptr2->share = flag;
  81. ptr2->localhub = vlocalhub;
  82. ptr2->buildts = vbuildts;
  83. strlcpy(ptr2->commit, vcommit, sizeof(ptr2->commit));
  84. if (vversion && vversion[0])
  85. strlcpy(ptr2->version, vversion, 121);
  86. ptr2->next = *ptr;
  87. *ptr = ptr2;
  88. /* May be via itself */
  89. ptr2->via = findbot(from);
  90. /* Look up the bot in internal users */
  91. ptr2->hub = is_hub(who);
  92. /* Cache user record */
  93. ptr2->u = userlist ? get_user_by_handle(userlist, who) : NULL;
  94. if (!egg_strcasecmp(next, conf.bot->nick))
  95. ptr2->uplink = (tand_t *) 1;
  96. else
  97. ptr2->uplink = findbot(next);
  98. tands++;
  99. }
  100. #ifdef G_BACKUP
  101. void check_should_backup()
  102. {
  103. struct chanset_t *chan = NULL;
  104. for (chan = chanset; chan; chan = chan->next) {
  105. if (chan->channel.backup_time && (chan->channel.backup_time < now) && !channel_backup(chan)) {
  106. do_chanset(NULL, chan, STR("+backup"), DO_LOCAL | DO_NET);
  107. chan->channel.backup_time = 0;
  108. }
  109. }
  110. }
  111. #endif /* G_BACKUP */
  112. void updatebot(int idx, char *who, char share, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion)
  113. {
  114. tand_t *ptr = findbot(who);
  115. if (ptr) {
  116. if (share)
  117. ptr->share = share;
  118. if (vlocalhub)
  119. ptr->localhub = vlocalhub;
  120. if (vbuildts)
  121. ptr->buildts = vbuildts;
  122. if (vcommit)
  123. strlcpy(ptr->commit, vcommit, sizeof(ptr->commit));
  124. if (vversion && vversion[0])
  125. strlcpy(ptr->version, vversion, 121);
  126. botnet_send_update(idx, ptr);
  127. }
  128. }
  129. /* New botnet member
  130. */
  131. int addparty(char *bot, char *nick, int chan, char flag, int sock, char *from, int *idx)
  132. {
  133. int i = 0;
  134. for (i = 0; i < parties; i++) {
  135. /* Just changing the channel of someone already on? */
  136. if (!egg_strcasecmp(party[i].bot, bot) && (party[i].sock == sock)) {
  137. int oldchan = party[i].chan;
  138. party[i].chan = chan;
  139. party[i].timer = now;
  140. if (from[0]) {
  141. if (flag == ' ')
  142. flag = '-';
  143. party[i].flag = flag;
  144. if (party[i].from)
  145. free(party[i].from);
  146. party[i].from = strdup(from);
  147. }
  148. *idx = i;
  149. return oldchan;
  150. }
  151. }
  152. /* New member */
  153. if (parties == maxparty) {
  154. maxparty += 50;
  155. party = (party_t *) my_realloc((void *) party, maxparty * sizeof(party_t));
  156. }
  157. strlcpy(party[parties].nick, nick, sizeof(party[parties].nick));
  158. strlcpy(party[parties].bot, bot, sizeof(party[parties].bot));
  159. party[parties].chan = chan;
  160. party[parties].sock = sock;
  161. party[parties].status = 0;
  162. party[parties].away = 0;
  163. party[parties].timer = now; /* cope. */
  164. if (from[0]) {
  165. if (flag == ' ')
  166. flag = '-';
  167. party[parties].flag = flag;
  168. party[parties].from = strdup(from);
  169. } else {
  170. party[parties].flag = ' ';
  171. party[parties].from = strdup("(unknown)");
  172. }
  173. *idx = parties;
  174. parties++;
  175. return -1;
  176. }
  177. /* Alter status flags for remote party-line user.
  178. */
  179. void partystat(char *bot, int sock, int add, int rem)
  180. {
  181. for (int i = 0; i < parties; i++) {
  182. if ((!egg_strcasecmp(party[i].bot, bot)) &&
  183. (party[i].sock == sock)) {
  184. party[i].status |= add;
  185. party[i].status &= ~rem;
  186. }
  187. }
  188. }
  189. /* Other bot is sharing idle info.
  190. */
  191. void partysetidle(char *bot, int sock, int secs)
  192. {
  193. for (int i = 0; i < parties; i++) {
  194. if ((!egg_strcasecmp(party[i].bot, bot)) &&
  195. (party[i].sock == sock)) {
  196. party[i].timer = (now - (time_t) secs);
  197. }
  198. }
  199. }
  200. /* Return someone's chat channel.
  201. */
  202. int getparty(char *bot, int sock)
  203. {
  204. for (int i = 0; i < parties; i++) {
  205. if (!egg_strcasecmp(party[i].bot, bot) &&
  206. (party[i].sock == sock)) {
  207. return i;
  208. }
  209. }
  210. return -1;
  211. }
  212. /* Un-idle someone
  213. */
  214. bool partyidle(char *bot, char *nick)
  215. {
  216. bool ok = 0;
  217. for (int i = 0; i < parties; i++) {
  218. if ((!egg_strcasecmp(party[i].bot, bot)) && (!egg_strcasecmp(party[i].nick, nick))) {
  219. party[i].timer = now;
  220. ok = 1;
  221. }
  222. }
  223. return ok;
  224. }
  225. /* Change someone's nick
  226. */
  227. int partynick(char *bot, int sock, char *nick)
  228. {
  229. char work[HANDLEN + 1] = "";
  230. for (int i = 0; i < parties; i++) {
  231. if (!egg_strcasecmp(party[i].bot, bot) && (party[i].sock == sock)) {
  232. strlcpy(work, party[i].nick, sizeof(work));
  233. strlcpy(party[i].nick, nick, sizeof(party[i].nick));
  234. strlcpy(nick, work, HANDLEN + 1);
  235. return i;
  236. }
  237. }
  238. return -1;
  239. }
  240. /* Set away message
  241. */
  242. void partyaway(char *bot, int sock, char *msg)
  243. {
  244. for (int i = 0; i < parties; i++) {
  245. if ((!egg_strcasecmp(party[i].bot, bot)) &&
  246. (party[i].sock == sock)) {
  247. if (party[i].away)
  248. free(party[i].away);
  249. if (msg[0]) {
  250. party[i].away = strdup(msg);
  251. } else
  252. party[i].away = 0;
  253. }
  254. }
  255. }
  256. /* Remove a tandem bot from the chain list
  257. */
  258. void rembot(const char *whoin)
  259. {
  260. tand_t **ptr = &tandbot, *ptr2 = NULL;
  261. char *who = strdup(whoin);
  262. while (*ptr) {
  263. if (!egg_strcasecmp((*ptr)->bot, who))
  264. break;
  265. ptr = &((*ptr)->next);
  266. }
  267. if (!*ptr) {
  268. /* May have just .unlink *'d */
  269. free(who);
  270. return;
  271. }
  272. struct userrec *u = get_user_by_handle(userlist, (char *) who);
  273. if (u)
  274. touch_laston(u, "unlinked", now);
  275. ptr2 = *ptr;
  276. *ptr = ptr2->next;
  277. free(ptr2);
  278. tands--;
  279. dupwait_notify(who);
  280. free(who);
  281. }
  282. void remparty(char *bot, int sock)
  283. {
  284. for (int i = 0; i < parties; i++)
  285. if ((!egg_strcasecmp(party[i].bot, bot)) &&
  286. (party[i].sock == sock)) {
  287. parties--;
  288. if (party[i].from)
  289. free(party[i].from);
  290. if (party[i].away)
  291. free(party[i].away);
  292. if (i < parties) {
  293. strlcpy(party[i].bot, party[parties].bot, sizeof(party[i].bot));
  294. strlcpy(party[i].nick, party[parties].nick, sizeof(party[i].nick));
  295. party[i].chan = party[parties].chan;
  296. party[i].sock = party[parties].sock;
  297. party[i].flag = party[parties].flag;
  298. party[i].status = party[parties].status;
  299. party[i].timer = party[parties].timer;
  300. party[i].from = party[parties].from;
  301. party[i].away = party[parties].away;
  302. }
  303. }
  304. }
  305. /* Cancel every user that was on a certain bot
  306. */
  307. void rempartybot(char *bot)
  308. {
  309. for (int i = 0; i < parties; i++)
  310. if (!egg_strcasecmp(party[i].bot, bot)) {
  311. remparty(bot, party[i].sock);
  312. i--;
  313. }
  314. }
  315. /* Remove every bot linked 'via' bot <x>
  316. */
  317. void unvia(int idx, tand_t *who)
  318. {
  319. if (!who)
  320. return; /* Safety */
  321. tand_t *bot = NULL, *bot2 = NULL;
  322. rempartybot(who->bot);
  323. bot = tandbot;
  324. while (bot) {
  325. if (bot->uplink == who) {
  326. unvia(idx, bot);
  327. bot2 = bot->next;
  328. rembot(bot->bot);
  329. bot = bot2;
  330. } else
  331. bot = bot->next;
  332. }
  333. }
  334. #ifdef NOTUSED
  335. void besthub(char *hub)
  336. {
  337. tand_t *ptr = tandbot;
  338. struct userrec *u = NULL, *besthubu = NULL;
  339. char bestlval[HANDLEN + 4] = "", lval[HANDLEN + 4] = "";
  340. hub[0] = 0;
  341. strlcpy(bestlval, "z", sizeof(bestlval));
  342. while (ptr) {
  343. u = get_user_by_handle(userlist, ptr->bot);
  344. if (u) {
  345. link_pref_val(u, lval);
  346. if (strcmp(lval, bestlval) < 0) {
  347. strlcpy(bestlval, lval, sizeof(bestlval));
  348. besthubu = u;
  349. }
  350. }
  351. ptr = ptr->next;
  352. }
  353. if (besthubu)
  354. strcpy(hub, besthubu->handle);
  355. return;
  356. }
  357. #endif
  358. /* Return index into dcc list of the bot that connects us to bot <x>
  359. */
  360. int nextbot(const char *who)
  361. {
  362. tand_t *bot = findbot(who);
  363. if (!bot)
  364. return -1;
  365. for (int j = 0; j < dcc_total; j++) {
  366. if (dcc[j].type && bot->via && !egg_strcasecmp(bot->via->bot, dcc[j].nick) && (dcc[j].type == &DCC_BOT))
  367. return j;
  368. }
  369. return -1; /* We're not connected to 'via' */
  370. }
  371. /* Return name of the bot that is directly connected to bot X
  372. */
  373. char *lastbot(const char *who)
  374. {
  375. tand_t *bot = findbot(who);
  376. if (!bot)
  377. return "*";
  378. else if (bot->uplink == (tand_t *) 1)
  379. return conf.bot->nick;
  380. else
  381. return bot->uplink->bot;
  382. }
  383. /* Modern version of 'whom' (use local data)
  384. */
  385. void answer_local_whom(int idx, int chan)
  386. {
  387. char format[81] = "", c = 0, idle[40] = "";
  388. int i, t, nicklen, botnicklen, total = 0;
  389. if (chan == (-1))
  390. dprintf(idx, "%s (+: %s, *: %s)\n", "Users across the botnet", "Party line", "Local channel");
  391. else if (chan > 0)
  392. dprintf(idx, "%s %s%d:\n", "Users on channel", (chan < GLOBAL_CHANS) ? "" : "*", chan % GLOBAL_CHANS);
  393. /* Find longest nick and botnick */
  394. nicklen = botnicklen = 0;
  395. for (i = 0; i < dcc_total; i++) {
  396. if (dcc[i].type && dcc[i].simul == -1 && dcc[i].type == &DCC_CHAT) {
  397. if ((chan == (-1)) || ((chan >= 0) && (dcc[i].u.chat->channel == chan))) {
  398. t = strlen(dcc[i].nick); if(t > nicklen) nicklen = t;
  399. t = strlen(conf.bot->nick); if(t > botnicklen) botnicklen = t;
  400. }
  401. }
  402. }
  403. for (i = 0; i < parties; i++) {
  404. if ((chan == (-1)) || ((chan >= 0) && (party[i].chan == chan))) {
  405. t = strlen(party[i].nick); if(t > nicklen) nicklen = t;
  406. t = strlen(party[i].bot); if(t > botnicklen) botnicklen = t;
  407. }
  408. }
  409. if(nicklen < 9) nicklen = 9;
  410. if(botnicklen < 9) botnicklen = 9;
  411. if (conf.bot->hub) {
  412. simple_snprintf(format, sizeof format, "%%-%us %%-%us %%s\n", nicklen, botnicklen);
  413. dprintf(idx, format, " Nick", " Bot", " Host");
  414. dprintf(idx, format, "----------", "---------", "--------------------");
  415. simple_snprintf(format, sizeof format, "%%c%%-%us %%c %%-%us %%s%%s\n", nicklen, botnicklen);
  416. } else {
  417. simple_snprintf(format, sizeof format, "%%-%us\n", nicklen);
  418. dprintf(idx, format, " Nick");
  419. dprintf(idx, format, "----------");
  420. simple_snprintf(format, sizeof format, "%%c%%-%us %%c %%s\n", nicklen);
  421. }
  422. for (i = 0; i < dcc_total; i++) {
  423. if (dcc[i].type && dcc[i].simul == -1 && dcc[i].type == &DCC_CHAT) {
  424. if ((chan == (-1)) || ((chan >= 0) && (dcc[i].u.chat->channel == chan))) {
  425. c = geticon(i);
  426. if (c == '-')
  427. c = ' ';
  428. if (now - dcc[i].timeval > 300) {
  429. unsigned long mydays, hrs, mins;
  430. mydays = (now - dcc[i].timeval) / 86400;
  431. hrs = ((now - dcc[i].timeval) - (mydays * 86400)) / 3600;
  432. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  433. if (mydays > 0)
  434. simple_snprintf(idle, sizeof(idle), " [idle %lud%luh]", mydays, hrs);
  435. else if (hrs > 0)
  436. simple_snprintf(idle, sizeof(idle), " [idle %luh%lum]", hrs, mins);
  437. else
  438. simple_snprintf(idle, sizeof(idle), " [idle %lum]", mins);
  439. } else
  440. idle[0] = 0;
  441. total++;
  442. if (conf.bot->hub)
  443. dprintf(idx, format, c, dcc[i].nick,
  444. (dcc[i].u.chat->channel == 0) && (chan == (-1)) ? '+' :
  445. (dcc[i].u.chat->channel > GLOBAL_CHANS) &&
  446. (chan == (-1)) ? '*' : ' ', conf.bot->nick, dcc[i].host, idle);
  447. else
  448. dprintf(idx, format, c, dcc[i].nick,
  449. (dcc[i].u.chat->channel == 0) && (chan == (-1)) ? '+' :
  450. (dcc[i].u.chat->channel > GLOBAL_CHANS) &&
  451. (chan == (-1)) ? '*' : ' ', idle);
  452. if (dcc[i].u.chat->away != NULL)
  453. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  454. if (dcc[i].u.chat->su_nick && (dcc[idx].user->flags & USER_ADMIN))
  455. dprintf(idx, " SU FROM: %s\n", dcc[i].u.chat->su_nick);
  456. }
  457. }
  458. }
  459. for (i = 0; i < parties; i++) {
  460. if ((chan == (-1)) || ((chan >= 0) && (party[i].chan == chan))) {
  461. c = party[i].flag;
  462. if (c == '-')
  463. c = ' ';
  464. if (party[i].timer == 0L)
  465. strlcpy(idle, " [idle?]", sizeof(idle));
  466. else if (now - party[i].timer > 300) {
  467. unsigned long mydays, hrs, mins;
  468. mydays = (now - party[i].timer) / 86400;
  469. hrs = ((now - party[i].timer) - (mydays * 86400)) / 3600;
  470. mins = ((now - party[i].timer) - (hrs * 3600)) / 60;
  471. if (mydays > 0)
  472. simple_snprintf(idle, sizeof(idle), " [idle %lud%luh]", mydays, hrs);
  473. else if (hrs > 0)
  474. simple_snprintf(idle, sizeof(idle), " [idle %luh%lum]", hrs, mins);
  475. else
  476. simple_snprintf(idle, sizeof(idle), " [idle %lum]", mins);
  477. } else
  478. idle[0] = 0;
  479. total++;
  480. if (conf.bot->hub)
  481. dprintf(idx, format, c, party[i].nick, (party[i].chan == 0) && (chan == (-1)) ? '+' : ' ',
  482. party[i].bot, party[i].from, idle);
  483. else
  484. dprintf(idx, format, c, party[i].nick, (party[i].chan == 0) && (chan == (-1)) ? '+' : ' ', idle);
  485. if (party[i].status & PLSTAT_AWAY)
  486. dprintf(idx, " AWAY: %s\n", party[i].away ? party[i].away : "");
  487. }
  488. }
  489. dprintf(idx, "Total users: %d\n", total);
  490. }
  491. /* Show z a list of all bots connected
  492. */
  493. void
  494. tell_bots(int idx, int up, const char *nodename)
  495. {
  496. struct userrec *u = NULL;
  497. int cnt = 0, tot = 0, total = 1, mtot = 0;
  498. char work[151] = "", *node = NULL;
  499. if (up) {
  500. if (nodename)
  501. node = (char *) get_user(&USERENTRY_NODENAME, conf.bot->u);
  502. if (!nodename || wild_match(nodename, node)) {
  503. strlcat(work, conf.bot->nick, sizeof(work));
  504. strlcat(work, " ", sizeof(work));
  505. cnt++;
  506. tot++;
  507. if (nodename)
  508. mtot++;
  509. }
  510. }
  511. for (u = userlist; u; u = u->next) {
  512. if (u->bot) {
  513. if (egg_strcasecmp(u->handle, conf.bot->nick)) {
  514. bool found = 0;
  515. if (findbot(u->handle))
  516. found = 1;
  517. total++;
  518. if (nodename || (!nodename && ((!up && !found) || (up && found)))) {
  519. if (nodename)
  520. node = (char *) get_user(&USERENTRY_NODENAME, u);
  521. if (!nodename || wild_match(nodename, node)) {
  522. if (nodename && !found)
  523. strlcat(work, "*", sizeof(work));
  524. strlcat(work, u->handle, sizeof(work));
  525. cnt++;
  526. if (nodename)
  527. mtot++;
  528. if (!nodename || (nodename && found))
  529. tot++;
  530. if (cnt == 11) {
  531. dprintf(idx, "%s bots: %s\n", nodename ? "Matching" : up ? "Up" : "Down", work);
  532. work[0] = 0;
  533. cnt = 0;
  534. } else {
  535. strlcat(work, " ", sizeof(work));
  536. }
  537. }
  538. }
  539. }
  540. }
  541. }
  542. if (work[0])
  543. dprintf(idx, "%s bot%s: %s\n", nodename ? "Matching" : up ? "Up" : "Down", cnt > 1 ? "s" : "", work);
  544. if (nodename)
  545. dprintf(idx, "(Total Matching: %d/%d)\n", mtot, total);
  546. dprintf(idx, "(Total %s: %d/%d)\n", nodename ? "up" : up ? "up" : "down", tot, nodename ? mtot : total);
  547. }
  548. /* Show a simpleton bot tree
  549. */
  550. void tell_bottree(int idx)
  551. {
  552. if (tands == 0) {
  553. dprintf(idx, "%s\n", "No bots linked.");
  554. return;
  555. }
  556. char s[161] = "", work[1024] = "", *color_str = NULL;
  557. tand_t *last[20] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  558. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
  559. tand_t *thisbot = NULL, *bot = NULL, *bot2 = NULL;
  560. int lev = 0, more = 1, mark[20], ok, cnt, i = 0, imark, tothops = 0;
  561. struct userrec *botu = NULL;
  562. for (bot = tandbot; bot; bot = bot->next)
  563. if (!bot->uplink) {
  564. if (i) {
  565. s[i++] = ',';
  566. s[i++] = ' ';
  567. }
  568. strlcpy(s + i, bot->bot, sizeof(s) - i);
  569. i += strlen(bot->bot);
  570. }
  571. if (bot_hublevel(conf.bot->u) < 999)
  572. color_str = (char *) YELLOW(idx);
  573. else if (conf.bot->localhub)
  574. color_str = (char *) RED(idx);
  575. else
  576. color_str = (char *) NULL;
  577. if (s[0])
  578. dprintf(idx, "(%s %s)\n", "No trace info for:", s);
  579. dprintf(idx, "%s%s%s (%s %s)\n", color_str ? color_str : "",
  580. conf.bot->nick,
  581. color_str ? COLOR_END(idx) : "",
  582. egg_version, commit);
  583. thisbot = (tand_t *) 1;
  584. work[0] = 0;
  585. while (more) {
  586. if (lev == 20) {
  587. dprintf(idx, "\n%s\n", "Tree too complex!");
  588. return;
  589. }
  590. cnt = 0;
  591. tothops += lev;
  592. for (bot = tandbot; bot; bot = bot->next)
  593. if (bot->uplink == thisbot)
  594. cnt++;
  595. if (cnt) {
  596. imark = 0;
  597. for (i = 0; i < lev; i++) {
  598. if (mark[i])
  599. strlcpy(work + imark, " | ", sizeof(work) - imark);
  600. else
  601. strlcpy(work + imark, " ", sizeof(work) - imark);
  602. imark += 5;
  603. }
  604. if (cnt > 1)
  605. strlcpy(work + imark, " |-", sizeof(work) - imark);
  606. else
  607. strlcpy(work + imark, " `-", sizeof(work) - imark);
  608. s[0] = 0;
  609. bot = tandbot;
  610. while (!s[0]) {
  611. if (bot->uplink == thisbot) {
  612. botu = get_user_by_handle(userlist, bot->bot);
  613. if (botu && bot_hublevel(botu) < 999)
  614. color_str = (char *) YELLOW(idx);
  615. else if (botu && bot->localhub)
  616. color_str = (char *) RED(idx);
  617. else
  618. color_str = (char *) NULL;
  619. if (bot->share)
  620. i = simple_snprintf(s, sizeof(s), "%c", bot->share);
  621. else
  622. i = simple_snprintf(s, sizeof(s), "-");
  623. i = simple_snprintf(s + 1, sizeof(s) - 1, "%s%s%s (%s %s)", color_str ? color_str : "",
  624. bot->bot,
  625. color_str ? COLOR_END(idx) : "",
  626. bot->version, bot->commit);
  627. } else
  628. bot = bot->next;
  629. }
  630. dprintf(idx, "%s%s\n", work, s);
  631. if (cnt > 1)
  632. mark[lev] = 1;
  633. else
  634. mark[lev] = 0;
  635. work[0] = 0;
  636. last[lev] = thisbot;
  637. thisbot = bot;
  638. lev++;
  639. more = 1;
  640. } else {
  641. while (cnt == 0) {
  642. /* No subtrees from here */
  643. if (lev == 0) {
  644. dprintf(idx, "(( tree error ))\n");
  645. return;
  646. }
  647. ok = 0;
  648. for (bot = tandbot; bot; bot = bot->next) {
  649. if (bot->uplink == last[lev - 1]) {
  650. if (thisbot == bot)
  651. ok = 1;
  652. else if (ok) {
  653. cnt++;
  654. if (cnt == 1) {
  655. botu = get_user_by_handle(userlist, bot->bot);
  656. if (botu && bot_hublevel(botu) < 999)
  657. color_str = (char *) YELLOW(idx);
  658. else if (botu && bot->localhub)
  659. color_str = (char *) RED(idx);
  660. else
  661. color_str = (char *) NULL;
  662. bot2 = bot;
  663. if (bot->share)
  664. i = simple_snprintf(s, sizeof(s), "%c", bot->share);
  665. else
  666. i = simple_snprintf(s, sizeof(s), "-");
  667. i = simple_snprintf(s + 1, sizeof(s) - 1, "%s%s%s (%s %s)", color_str ? color_str : "",
  668. bot->bot,
  669. color_str ? COLOR_END(idx) : "",
  670. bot->version, bot->commit);
  671. }
  672. }
  673. }
  674. }
  675. if (cnt) {
  676. imark = 0;
  677. for (i = 1; i < lev; i++) {
  678. if (mark[i - 1])
  679. strlcpy(work + imark, " | ", sizeof(work) - imark);
  680. else
  681. strlcpy(work + imark, " ", sizeof(work) - imark);
  682. imark += 5;
  683. }
  684. more = 1;
  685. if (cnt > 1)
  686. dprintf(idx, "%s |-%s\n", work, s);
  687. else
  688. dprintf(idx, "%s `-%s\n", work, s);
  689. thisbot = bot2;
  690. work[0] = 0;
  691. if (cnt > 1)
  692. mark[lev - 1] = 1;
  693. else
  694. mark[lev - 1] = 0;
  695. } else {
  696. /* This was the last child */
  697. lev--;
  698. if (lev == 0) {
  699. more = 0;
  700. cnt = 999;
  701. } else {
  702. more = 1;
  703. thisbot = last[lev];
  704. }
  705. }
  706. }
  707. }
  708. }
  709. /* Hop information: (9d) */
  710. dprintf(idx, "Average hops: %3.1f, total bots: %d\n", ((float) tothops) / ((float) tands), tands + 1);
  711. }
  712. /* Dump list of links to a new bot
  713. */
  714. void dump_links(int z)
  715. {
  716. register int i;
  717. register size_t l;
  718. char x[1024] = "";
  719. if (conf.bot->hub) {
  720. tand_t *bot = NULL;
  721. char *p = NULL;
  722. for (bot = tandbot; bot; bot = bot->next) {
  723. if (bot->uplink == (tand_t *) 1)
  724. p = conf.bot->nick;
  725. else
  726. p = bot->uplink->bot;
  727. l = simple_snprintf(x, sizeof(x), "n %s %s %cD0gc %d %d %s %s\n", bot->bot, p, bot->share, bot->localhub,
  728. (int) bot->buildts, bot->commit, bot->version ? bot->version : "");
  729. tputs(dcc[z].sock, x, l);
  730. }
  731. }
  732. /* Dump party line members */
  733. for (i = 0; i < dcc_total; i++) {
  734. if (dcc[i].type && dcc[i].type == &DCC_CHAT && dcc[i].simul == -1) {
  735. if ((dcc[i].u.chat->channel >= 0) && (dcc[i].u.chat->channel < GLOBAL_CHANS)) {
  736. l = simple_snprintf2(x, sizeof(x), "j !%s %s %D %c%D %s\n", conf.bot->nick, dcc[i].nick,
  737. dcc[i].u.chat->channel, geticon(i), dcc[i].sock, dcc[i].host);
  738. tputs(dcc[z].sock, x, l);
  739. l = simple_snprintf2(x, sizeof(x), "i %s %D %D %s\n", conf.bot->nick,
  740. dcc[i].sock, now - dcc[i].timeval,
  741. dcc[i].u.chat->away ? dcc[i].u.chat->away : "");
  742. tputs(dcc[z].sock, x, l);
  743. }
  744. }
  745. }
  746. for (i = 0; i < parties; i++) {
  747. l = simple_snprintf2(x, sizeof(x), "j %s %s %D %c%D %s\n", party[i].bot, party[i].nick,
  748. party[i].chan, party[i].flag, party[i].sock, party[i].from);
  749. tputs(dcc[z].sock, x, l);
  750. if ((party[i].status & PLSTAT_AWAY) || (party[i].timer != 0)) {
  751. l = simple_snprintf2(x, sizeof(x), "i %s %D %D %s\n", party[i].bot, party[i].sock, now - party[i].timer, party[i].away ? party[i].away : "");
  752. tputs(dcc[z].sock, x, l);
  753. }
  754. }
  755. }
  756. int in_chain(char *who)
  757. {
  758. if (!egg_strcasecmp(who, conf.bot->nick))
  759. return 1;
  760. if (findbot(who))
  761. return 1;
  762. return 0;
  763. }
  764. int bots_in_subtree(tand_t *bot)
  765. {
  766. if (!bot)
  767. return 0;
  768. int nr = 1;
  769. tand_t *b = NULL;
  770. for (b = tandbot; b; b = b->next) {
  771. if (b->bot && (b->uplink == bot)) {
  772. nr += bots_in_subtree(b);
  773. }
  774. }
  775. return nr;
  776. }
  777. int users_in_subtree(tand_t *bot)
  778. {
  779. if (!bot)
  780. return 0;
  781. int i, nr = 0;
  782. tand_t *b = NULL;
  783. for (i = 0; i < parties; i++)
  784. if (!egg_strcasecmp(party[i].bot, bot->bot))
  785. nr++;
  786. for (b = tandbot; b; b = b->next)
  787. if (b->bot && (b->uplink == bot))
  788. nr += users_in_subtree(b);
  789. return nr;
  790. }
  791. /* Break link with a tandembot
  792. */
  793. int botunlink(int idx, const char *nick, const char *reason)
  794. {
  795. register int i;
  796. int bots, users;
  797. tand_t *bot = NULL;
  798. if (nick[0] == '*')
  799. dprintf(idx, "%s\n", "Unlinking all bots...");
  800. for (i = 0; i < dcc_total; i++) {
  801. if (dcc[i].type && ((nick[0] == '*') || !egg_strcasecmp(dcc[i].nick, nick))) {
  802. if (dcc[i].type == &DCC_FORK_BOT) {
  803. if (idx >= 0)
  804. dprintf(idx, "%s: %s -> %s.\n", "Killed link attempt to",
  805. dcc[i].nick, dcc[i].host);
  806. putlog(LOG_BOTS, "*", "%s: %s -> %s:%d",
  807. "Killed link attempt to", dcc[i].nick,
  808. dcc[i].host, dcc[i].port);
  809. killsock(dcc[i].sock);
  810. lostdcc(i);
  811. if (nick[0] != '*')
  812. return 1;
  813. } else if (dcc[i].type == &DCC_BOT_NEW) {
  814. if (idx >= 0)
  815. dprintf(idx, "%s %s.\n", "No longer trying to link:",
  816. dcc[i].nick);
  817. putlog(LOG_BOTS, "*", "%s %s @ %s:%d",
  818. "Stopped trying to link", dcc[i].nick,
  819. dcc[i].host, dcc[i].port);
  820. killsock(dcc[i].sock);
  821. lostdcc(i);
  822. if (nick[0] != '*')
  823. return 1;
  824. } else if (dcc[i].type == &DCC_BOT) {
  825. char s[1024] = "";
  826. if (idx >= 0)
  827. dprintf(idx, "%s %s.\n", "Breaking link with", dcc[i].nick);
  828. else if ((idx == -3) && (b_status(i) & STAT_SHARE) && !share_unlinks)
  829. return -1;
  830. bot = findbot(dcc[i].nick);
  831. bots = bots_in_subtree(bot);
  832. users = users_in_subtree(bot);
  833. if (reason && reason[0]) {
  834. simple_snprintf(s, sizeof(s), "%s %s (%s) (lost %d bot%s and %d user%s)",
  835. "Unlinked from:", dcc[i].nick, reason, bots,
  836. (bots != 1) ? "s" : "", users, (users != 1) ?
  837. "s" : "");
  838. dprintf(i, "bye %s\n", reason);
  839. } else {
  840. simple_snprintf(s, sizeof(s), "%s %s (lost %d bot%s and %d user%s)",
  841. "Unlinked from:", dcc[i].nick, bots, (bots != 1) ?
  842. "s" : "", users, (users != 1) ? "s" : "");
  843. dprintf(i, "bye No reason\n");
  844. }
  845. chatout("*** %s\n", s);
  846. botnet_send_unlinked(i, dcc[i].nick, s);
  847. killsock(dcc[i].sock);
  848. lostdcc(i);
  849. if (nick[0] != '*')
  850. return 1;
  851. }
  852. }
  853. }
  854. if (idx >= 0 && nick[0] != '*')
  855. dprintf(idx, "%s\n", "Not connected to that bot.");
  856. if (nick[0] != '*') {
  857. bot = findbot(nick);
  858. if (bot) {
  859. /* The internal bot list is desynched from the dcc list
  860. sometimes. While we still search for the bug, provide
  861. an easy way to clear out those `ghost'-bots.
  862. Fabian (2000-08-02) */
  863. char *ghost = "BUG!!: Found bot `%s' in internal bot list, but it\n"
  864. " shouldn't have been there! Removing.\n"
  865. " This is a known bug we haven't fixed yet. If this\n"
  866. " bot is the newest eggdrop version available and you\n"
  867. " know a *reliable* way to reproduce the bug, please\n"
  868. " contact us - we need your help!\n";
  869. if (idx >= 0)
  870. dprintf(idx, ghost, nick);
  871. else
  872. putlog(LOG_MISC, "*", ghost, nick);
  873. rembot(bot->bot);
  874. return 1;
  875. }
  876. }
  877. if (nick[0] == '*') {
  878. dprintf(idx, "%s\n", "Smooshing bot tables and assocs...");
  879. while (tandbot)
  880. rembot(tandbot->bot);
  881. while (parties) {
  882. parties--;
  883. }
  884. }
  885. return 0;
  886. }
  887. static void botlink_dns_callback(int, void *, const char *, char **);
  888. /* Link to another bot
  889. */
  890. int botlink(char *linker, int idx, char *nick)
  891. {
  892. struct userrec *u = get_user_by_handle(userlist, nick);
  893. if (!u || !u->bot) {
  894. if (idx >= 0)
  895. dprintf(idx, "%s %s\n", nick, "is not a known bot.");
  896. } else if (!egg_strcasecmp(nick, conf.bot->nick)) {
  897. if (idx >= 0)
  898. dprintf(idx, "%s\n", "Link to myself? Oh boy, Freud would have a field day.");
  899. } else if (in_chain(nick) && (idx != -3)) {
  900. if (idx >= 0)
  901. dprintf(idx, "That bot is already connected up.\n");
  902. } else {
  903. register int i;
  904. for (i = 0; i < dcc_total; i++) {
  905. if (dcc[i].type && (dcc[i].user == u) &&
  906. ((dcc[i].type == &DCC_FORK_BOT) ||
  907. (dcc[i].type == &DCC_BOT_NEW))) {
  908. if (idx >= 0)
  909. dprintf(idx, "Already linking to that bot\n");
  910. return 0;
  911. }
  912. }
  913. /* Address to connect to is in 'info' */
  914. struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
  915. if (!bi || !strlen(bi->address) || !bi->telnet_port || (bi->telnet_port <= 0)) {
  916. if (idx >= 0) {
  917. dprintf(idx, "Invalid telnet address:port stored for '%s'.\n", nick);
  918. dprintf(idx, "Use: %schaddr %s <address>:<port#>[/<relay-port#>]\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "", nick);
  919. }
  920. } else if (dcc_total == max_dcc) {
  921. if (idx >= 0)
  922. dprintf(idx, "%s\n", "Sorry, too many DCC connections.");
  923. } else {
  924. correct_handle(nick);
  925. if (idx > -2)
  926. putlog(LOG_BOTS, "*", "Linking to %s at %s:%d ...", nick,
  927. bi->address, bi->telnet_port);
  928. i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  929. dcc[i].timeval = now;
  930. dcc[i].port = bi->telnet_port;
  931. dcc[i].user = u;
  932. strlcpy(dcc[i].nick, nick, NICKLEN);
  933. strlcpy(dcc[i].host, bi->address, UHOSTLEN);
  934. dcc[i].u.dns->cptr = strdup(linker);
  935. dcc[i].u.dns->ibuf = idx;
  936. dcc[i].bot = 1;
  937. int dns_id = egg_dns_lookup(bi->address, 20, botlink_dns_callback, (void *) (long)i);
  938. /* dns_id
  939. * -1 means it was cached and the callback already called
  940. * -2 means it's already being looked up.. try again later .. */
  941. if (dns_id >= 0)
  942. dcc[i].dns_id = dns_id;
  943. else if (dns_id == -2) {
  944. lostdcc(i);
  945. return 0;
  946. }
  947. return 1;
  948. /* wait for async reply */
  949. }
  950. }
  951. return 0;
  952. }
  953. static void botlink_dns_callback(int id, void *client_data, const char *host, char **ips)
  954. {
  955. long data = (long) client_data;
  956. int i = (int) data;
  957. if (!valid_dns_id(i, id))
  958. return;
  959. int idx = -1;
  960. char *linker = NULL;
  961. if (valid_idx(i)) {
  962. idx = dcc[i].u.dns->ibuf;
  963. linker = strdup(dcc[i].u.dns->cptr);
  964. }
  965. if (!ips) {
  966. lostdcc(i);
  967. return;
  968. }
  969. dcc[i].addr = inet_addr(ips[0]);
  970. changeover_dcc(i, &DCC_FORK_BOT, sizeof(struct bot_info));
  971. dcc[i].timeval = now;
  972. struct bot_info dummy;
  973. strlcpy(dcc[i].u.bot->version, "(primitive bot)", sizeof(dummy.version));
  974. strlcpy(dcc[i].u.bot->sysname, "*", 2);
  975. strlcpy(dcc[i].u.bot->linker, linker, sizeof(dummy.linker));
  976. dcc[i].u.bot->numver = idx;
  977. free(linker);
  978. dcc[i].u.bot->port = dcc[i].port; /* Remember where i started */
  979. #ifdef USE_IPV6
  980. dcc[i].sock = getsock(SOCK_STRONGCONN, is_dotted_ip(ips[0]));
  981. #else
  982. dcc[i].sock = getsock(SOCK_STRONGCONN);
  983. #endif /* USE_IPV6 */
  984. // if (dcc[i].sock > 0)
  985. // identd_open(); /* will be closed when an ident is replied. */
  986. if (dcc[i].sock < 0 || open_telnet_raw(dcc[i].sock, ips[0], dcc[i].port, 0, 1) < 0)
  987. failed_link(i);
  988. else { /* let's attempt to initiate SSL before ANYTHING else... */
  989. #ifdef HAVE_SSL
  990. /* if (!ssl_link(dcc[i].sock, CONNECT_SSL)) {
  991. debug2("back from ssl_link(%d, %d) for botlink (failed)", dcc[i].sock, CONNECT_SSL);
  992. dcc[i].ssl = 0;
  993. putlog(LOG_BOTS, "*", "SSL link for '%s' failed", dcc[i].nick);
  994. } else */
  995. dcc[i].ssl = 1;
  996. #else
  997. dcc[i].ssl = 0;
  998. #endif /* HAVE_SSL */
  999. }
  1000. /* wait for async reply */
  1001. }
  1002. static void failed_tandem_relay(int idx)
  1003. {
  1004. int uidx = (-1), i;
  1005. for (i = 0; i < dcc_total; i++) {
  1006. if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) &&
  1007. (dcc[i].u.relay->sock == dcc[idx].sock))
  1008. uidx = i;
  1009. }
  1010. if (uidx < 0) {
  1011. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1012. if (dcc[idx].sock != -1) {
  1013. killsock(dcc[idx].sock);
  1014. dcc[idx].sock = -1;
  1015. }
  1016. lostdcc(idx);
  1017. return;
  1018. }
  1019. struct chat_info *ci = dcc[uidx].u.relay->chat;
  1020. dprintf(uidx, "Could not relay to %s.\n", dcc[idx].nick);
  1021. dcc[uidx].status = dcc[uidx].u.relay->old_status;
  1022. free(dcc[uidx].u.relay);
  1023. dcc[uidx].u.chat = ci;
  1024. dcc[uidx].type = &DCC_CHAT;
  1025. if (dcc[idx].sock != -1) {
  1026. killsock(dcc[idx].sock);
  1027. dcc[idx].sock = -1;
  1028. }
  1029. lostdcc(idx);
  1030. return;
  1031. }
  1032. static void tandem_relay_dns_callback(int, void *, const char *, char **);
  1033. /* Relay to another tandembot
  1034. */
  1035. void tandem_relay(int idx, char *nick, register int i)
  1036. {
  1037. struct userrec *u = get_user_by_handle(userlist, nick);
  1038. if (!u || !u->bot) {
  1039. dprintf(idx, "%s %s\n", nick, "is not a known bot.");
  1040. return;
  1041. }
  1042. if (!egg_strcasecmp(nick, conf.bot->nick)) {
  1043. dprintf(idx, "%s\n", "Relay to myself? What on EARTH would be the point?!");
  1044. return;
  1045. }
  1046. /* Address to connect to is in 'info' */
  1047. struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
  1048. if (!bi || !strlen(bi->address) || !bi->relay_port || (bi->relay_port <= 0)) {
  1049. dprintf(idx, "Invalid telnet address:port stored for '%s'.\n", nick);
  1050. dprintf(idx, "Use: %schaddr %s <address>:<port#>[/<relay-port#>]\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "", nick);
  1051. return;
  1052. }
  1053. i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  1054. if (i < 0) {
  1055. dprintf(idx, "%s\n", "Sorry, too many DCC connections.");
  1056. return;
  1057. }
  1058. dcc[i].port = bi->relay_port;
  1059. dcc[i].addr = 0L;
  1060. strlcpy(dcc[i].nick, nick, NICKLEN);
  1061. dcc[i].user = u;
  1062. strlcpy(dcc[i].host, bi->address, UHOSTLEN);
  1063. if (conf.bot->hub)
  1064. dprintf(idx, "%s %s @ %s:%d ...\n", "Connecting to", nick, bi->address, bi->relay_port);
  1065. dprintf(idx, "(Type *BYE* on a line by itself to abort.)\n");
  1066. dcc[idx].type = &DCC_PRE_RELAY;
  1067. struct chat_info *ci = dcc[idx].u.chat;
  1068. dcc[idx].u.relay = (struct relay_info *) my_calloc(1, sizeof(struct relay_info));
  1069. dcc[idx].u.relay->chat = ci;
  1070. dcc[idx].u.relay->old_status = dcc[idx].status;
  1071. dcc[idx].u.relay->idx = i;
  1072. dcc[idx].u.relay->sock = -1;
  1073. dcc[i].timeval = now;
  1074. dcc[i].u.dns->ibuf = idx;
  1075. int dns_id = egg_dns_lookup(bi->address, 20, tandem_relay_dns_callback, (void *) (long) i);
  1076. if (dns_id >= 0)
  1077. dcc[i].dns_id = dns_id;
  1078. return;
  1079. /* wait for async reply */
  1080. }
  1081. static void tandem_relay_dns_callback(int id, void *client_data, const char *host, char **ips)
  1082. {
  1083. //64bit hacks
  1084. long data = (long) client_data;
  1085. int i = (int) data, idx = -1;
  1086. if (!valid_dns_id(i, id))
  1087. return;
  1088. if (valid_idx(i))
  1089. idx = dcc[i].u.dns->ibuf;
  1090. if (idx < 0) {
  1091. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", i, idx);
  1092. lostdcc(i);
  1093. return;
  1094. }
  1095. if (!ips) {
  1096. struct chat_info *ci = dcc[idx].u.relay->chat;
  1097. dprintf(idx, "Could not relay to %s.\n", dcc[i].nick);
  1098. dcc[idx].status = dcc[idx].u.relay->old_status;
  1099. free(dcc[idx].u.relay);
  1100. dcc[idx].u.chat = ci;
  1101. dcc[idx].type = &DCC_CHAT;
  1102. lostdcc(i);
  1103. return;
  1104. }
  1105. #ifdef USE_IPV6
  1106. int af = is_dotted_ip(ips[0]);
  1107. dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, af);
  1108. #else
  1109. dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
  1110. #endif /* USE_IPV6 */
  1111. if (dcc[i].sock < 0) {
  1112. lostdcc(i);
  1113. dprintf(idx, "No free sockets available.\n");
  1114. return;
  1115. }
  1116. dcc[idx].u.relay->sock = dcc[i].sock;
  1117. changeover_dcc(i, &DCC_FORK_RELAY, sizeof(struct relay_info));
  1118. dcc[i].addr = inet_addr(ips[0]);
  1119. dcc[i].u.relay->chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
  1120. dcc[i].u.relay->sock = dcc[idx].sock;
  1121. dcc[i].u.relay->port = dcc[i].port;
  1122. #ifdef USE_IPV6
  1123. dcc[i].u.relay->af = af;
  1124. #endif
  1125. dcc[i].u.relay->chat->away = NULL;
  1126. dcc[i].u.relay->chat->msgs_per_sec = 0;
  1127. dcc[i].u.relay->chat->con_flags = 0;
  1128. dcc[i].u.relay->chat->buffer = NULL;
  1129. dcc[i].u.relay->chat->max_line = 0;
  1130. dcc[i].u.relay->chat->line_count = 0;
  1131. dcc[i].u.relay->chat->current_lines = 0;
  1132. dcc[i].timeval = now;
  1133. if (open_telnet_raw(dcc[i].sock, ips[0], dcc[i].port, 0) < 0)
  1134. failed_tandem_relay(i);
  1135. }
  1136. /* Input from user before connect is ready
  1137. */
  1138. static void pre_relay(int idx, char *buf, register int len)
  1139. {
  1140. register int tidx = (-1), i;
  1141. for (i = 0; i < dcc_total; i++) {
  1142. if (dcc[i].type && dcc[i].type == &DCC_FORK_RELAY && (dcc[i].u.relay->sock == dcc[idx].sock)) {
  1143. tidx = i;
  1144. break;
  1145. }
  1146. }
  1147. if (tidx < 0) {
  1148. /* Now try to find it among the DNSWAIT sockets instead. */
  1149. for (i = 0; i < dcc_total; i++) {
  1150. if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT && (dcc[idx].u.relay->idx == i))) {
  1151. tidx = i;
  1152. break;
  1153. }
  1154. }
  1155. }
  1156. if (tidx < 0) {
  1157. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1158. killsock(dcc[idx].sock);
  1159. lostdcc(idx);
  1160. return;
  1161. }
  1162. if (!egg_strcasecmp(buf, "*bye*")) {
  1163. /* Disconnect */
  1164. struct chat_info *ci = dcc[idx].u.relay->chat;
  1165. dprintf(idx, "Aborting relay attempt to %s.\n", dcc[tidx].nick);
  1166. dprintf(idx, "You are now back on %s.\n\n", conf.bot->nick);
  1167. putlog(LOG_MISC, "*", "Relay aborted: %s -> %s", dcc[idx].nick, dcc[tidx].nick);
  1168. dcc[idx].status = dcc[idx].u.relay->old_status;
  1169. free(dcc[idx].u.relay);
  1170. dcc[idx].u.chat = ci;
  1171. dcc[idx].type = &DCC_CHAT;
  1172. if (dcc[tidx].sock != -1)
  1173. killsock(dcc[tidx].sock);
  1174. lostdcc(tidx);
  1175. return;
  1176. }
  1177. }
  1178. /* User disconnected before her relay had finished connecting
  1179. */
  1180. static void failed_pre_relay(int idx)
  1181. {
  1182. register int tidx = (-1), i;
  1183. for (i = 0; i < dcc_total; i++) {
  1184. if (dcc[i].type && (dcc[i].type == &DCC_FORK_RELAY) &&
  1185. (dcc[i].u.relay->sock == dcc[idx].sock)) {
  1186. tidx = i;
  1187. break;
  1188. }
  1189. }
  1190. if (tidx < 0) {
  1191. /* Now try to find it among the DNSWAIT sockets instead. */
  1192. for (i = 0; i < dcc_total; i++) {
  1193. if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT && (dcc[idx].u.relay->idx == i))) {
  1194. tidx = i;
  1195. break;
  1196. }
  1197. }
  1198. }
  1199. if (tidx < 0) {
  1200. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1201. killsock(dcc[idx].sock);
  1202. lostdcc(idx);
  1203. return;
  1204. }
  1205. putlog(LOG_MISC, "*", "%s [%s]%s/%d", "Lost dcc connection to", dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  1206. putlog(LOG_MISC, "*", "(%s %s)", "Dropping relay attempt to", dcc[tidx].nick);
  1207. if ((dcc[tidx].sock != STDOUT) || backgrd) {
  1208. if (idx > tidx) {
  1209. int t = tidx;
  1210. tidx = idx;
  1211. idx = t;
  1212. }
  1213. if (dcc[tidx].sock != -1)
  1214. killsock(dcc[tidx].sock);
  1215. lostdcc(tidx);
  1216. } else {
  1217. fatal("Lost my terminal?!", 0);
  1218. }
  1219. if (dcc[idx].sock != -1)
  1220. killsock(dcc[idx].sock);
  1221. lostdcc(idx);
  1222. }
  1223. static void cont_tandem_relay(int idx, char *buf, register int len)
  1224. {
  1225. register int uidx = (-1), i;
  1226. struct relay_info *ri = NULL;
  1227. for (i = 0; i < dcc_total; i++) {
  1228. if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) && (dcc[i].u.relay->sock == dcc[idx].sock))
  1229. uidx = i;
  1230. }
  1231. if (uidx < 0) {
  1232. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1233. killsock(dcc[idx].sock);
  1234. lostdcc(idx);
  1235. return;
  1236. }
  1237. dcc[idx].type = &DCC_RELAY;
  1238. dcc[idx].u.relay->sock = dcc[uidx].sock;
  1239. dcc[uidx].u.relay->sock = dcc[idx].sock;
  1240. dprintf(uidx, "%s %s ...\n", "Success!\n\nNOW CONNECTED TO RELAY BOT", dcc[idx].nick);
  1241. dprintf(uidx, "(You can type *BYE* to prematurely close the connection.)\n\n");
  1242. putlog(LOG_MISC, "*", "%s %s -> %s", "Relay link:",
  1243. dcc[uidx].nick, dcc[idx].nick);
  1244. ri = dcc[uidx].u.relay;
  1245. dcc[uidx].type = &DCC_CHAT;
  1246. dcc[uidx].u.chat = ri->chat;
  1247. if (dcc[uidx].u.chat->channel >= 0) {
  1248. chanout_but(-1, dcc[uidx].u.chat->channel, "*** %s left the party line.\n", dcc[uidx].nick);
  1249. if (dcc[uidx].u.chat->channel < GLOBAL_CHANS)
  1250. botnet_send_part_idx(uidx, NULL);
  1251. }
  1252. check_bind_chof(dcc[uidx].nick, uidx);
  1253. dcc[uidx].type = &DCC_RELAYING;
  1254. dcc[uidx].u.relay = ri;
  1255. }
  1256. static void eof_dcc_relay(int idx)
  1257. {
  1258. register int j;
  1259. for (j = 0; j < dcc_total; j++)
  1260. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock)
  1261. break;
  1262. if (j == dcc_total || !dcc[j].type) {
  1263. killsock(dcc[idx].sock);
  1264. lostdcc(idx);
  1265. return;
  1266. }
  1267. dcc[j].status = dcc[j].u.relay->old_status;
  1268. /* In case echo was off, turn it back on (send IAC WON'T ECHO): */
  1269. if (dcc[j].status & STAT_TELNET)
  1270. dprintf(j, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  1271. putlog(LOG_MISC, "*", "%s: %s -> %s", "Ended relay link", dcc[j].nick,
  1272. dcc[idx].nick);
  1273. dprintf(j, "\n\n*** %s %s\n", "RELAY CONNECTION DROPPED.\nYou are now back on", conf.bot->nick);
  1274. struct chat_info *ci = dcc[j].u.relay->chat;
  1275. free(dcc[j].u.relay);
  1276. dcc[j].u.chat = ci;
  1277. dcc[j].type = &DCC_CHAT;
  1278. if (dcc[j].u.chat->channel >= 0) {
  1279. chanout_but(-1, dcc[j].u.chat->channel, "*** %s %s.\n",
  1280. dcc[j].nick, "rejoined the party line.");
  1281. if (dcc[j].u.chat->channel < GLOBAL_CHANS)
  1282. botnet_send_join_idx(j);
  1283. }
  1284. check_bind_chon(dcc[j].nick, j);
  1285. killsock(dcc[idx].sock);
  1286. lostdcc(idx);
  1287. }
  1288. static void eof_dcc_relaying(int idx)
  1289. {
  1290. register int j, x = dcc[idx].u.relay->sock;
  1291. putlog(LOG_MISC, "*", "%s [%s]%s/%d", "Lost dcc connection to", dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  1292. killsock(dcc[idx].sock);
  1293. lostdcc(idx);
  1294. for (j = 0; j < dcc_total; j++)
  1295. if (dcc[j].type && dcc[j].sock == x && dcc[j].type != &DCC_FORK_RELAY)
  1296. break;
  1297. putlog(LOG_MISC, "*", "(%s %s)", "Dropping relay link to", dcc[j].nick);
  1298. killsock(dcc[j].sock);
  1299. lostdcc(j); /* Drop connection to the bot */
  1300. }
  1301. static void dcc_relay(int idx, char *buf, int j)
  1302. {
  1303. unsigned char *p = (unsigned char *) buf;
  1304. int mark;
  1305. for (j = 0; j < dcc_total; j++)
  1306. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAYING)
  1307. break;
  1308. /* If redirecting to a non-telnet user, swallow telnet codes and
  1309. escape sequences. */
  1310. if (!(dcc[j].status & STAT_TELNET)) {
  1311. while (*p != 0) {
  1312. while (*p && *p != 255 && *p != '\r')
  1313. p++; /* Search for IAC, escape sequences and CR. */
  1314. if (*p == 255) {
  1315. mark = 2;
  1316. if (!*(p + 1))
  1317. mark = 1; /* Bogus */
  1318. if ((*(p + 1) >= 251) || (*(p + 1) <= 254)) {
  1319. mark = 3;
  1320. if (!*(p + 2))
  1321. mark = 2; /* Bogus */
  1322. }
  1323. strcpy((char *) p, (char *) (p + mark));
  1324. } else if (*p == '\r')
  1325. strcpy((char *) p, (char *) (p + 1));
  1326. }
  1327. if (!buf[0])
  1328. dprintf(-dcc[idx].u.relay->sock, " \n");
  1329. else
  1330. dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
  1331. return;
  1332. }
  1333. /* Telnet user */
  1334. if (!buf[0])
  1335. dprintf(-dcc[idx].u.relay->sock, " \r\n");
  1336. else
  1337. dprintf(-dcc[idx].u.relay->sock, "%s\r\n", buf);
  1338. }
  1339. static void dcc_relaying(int idx, char *buf, int j)
  1340. {
  1341. if (egg_strcasecmp(buf, "*bye*")) {
  1342. dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
  1343. return;
  1344. }
  1345. /* The user want's to abort, so return them to partyline */
  1346. for (j = 0; j < dcc_total; j++)
  1347. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAY)
  1348. break;
  1349. dcc[idx].status = dcc[idx].u.relay->old_status;
  1350. /* In case echo was off, turn it back on (send IAC WON'T ECHO): */
  1351. if (dcc[idx].status & STAT_TELNET)
  1352. dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  1353. dprintf(idx, "\n(%s %s.)\n", "Breaking connection to", dcc[j].nick);
  1354. dprintf(idx, "You are now back on %s.\n\n", conf.bot->nick);
  1355. putlog(LOG_MISC, "*", "%s: %s -> %s", "Relay broken", dcc[idx].nick, dcc[j].nick);
  1356. if (dcc[idx].u.relay->chat->channel >= 0) {
  1357. chanout_but(-1, dcc[idx].u.relay->chat->channel, "*** %s joined the party line.\n", dcc[idx].nick);
  1358. if (dcc[idx].u.relay->chat->channel < GLOBAL_CHANS)
  1359. botnet_send_join_idx(idx);
  1360. }
  1361. struct chat_info *ci = dcc[idx].u.relay->chat;
  1362. free(dcc[idx].u.relay);
  1363. dcc[idx].u.chat = ci;
  1364. dcc[idx].type = &DCC_CHAT;
  1365. check_bind_chon(dcc[idx].nick, idx);
  1366. if (dcc[j].sock != -1)
  1367. killsock(dcc[j].sock);
  1368. lostdcc(j);
  1369. }
  1370. static void display_relay(int i, char *other, size_t bufsiz)
  1371. {
  1372. simple_snprintf(other, bufsiz, "rela -> sock %d", dcc[i].u.relay->sock);
  1373. }
  1374. static void display_relaying(int i, char *other, size_t bufsiz)
  1375. {
  1376. simple_snprintf(other, bufsiz, ">rly -> sock %d", dcc[i].u.relay->sock);
  1377. }
  1378. static void display_tandem_relay(int i, char *other, size_t bufsiz)
  1379. {
  1380. strlcpy(other, "other rela", bufsiz);
  1381. }
  1382. static void display_pre_relay(int i, char *other, size_t bufsiz)
  1383. {
  1384. strlcpy(other, "other >rly", bufsiz);
  1385. }
  1386. static void kill_relay(int idx, void *x)
  1387. {
  1388. register struct relay_info *p = (struct relay_info *) x;
  1389. if (p->chat)
  1390. DCC_CHAT.kill(idx, p->chat);
  1391. free(p);
  1392. }
  1393. struct dcc_table DCC_RELAY =
  1394. {
  1395. "RELAY",
  1396. 0, /* Flags */
  1397. eof_dcc_relay,
  1398. dcc_relay,
  1399. NULL,
  1400. NULL,
  1401. display_relay,
  1402. kill_relay,
  1403. NULL,
  1404. NULL
  1405. };
  1406. static void out_relay(int idx, char *buf, void *x)
  1407. {
  1408. register struct relay_info *p = (struct relay_info *) x;
  1409. if (p && p->chat)
  1410. DCC_CHAT.output(idx, buf, p->chat);
  1411. else
  1412. tputs(dcc[idx].sock, buf, strlen(buf));
  1413. }
  1414. struct dcc_table DCC_RELAYING =
  1415. {
  1416. "RELAYING",
  1417. 0, /* Flags */
  1418. eof_dcc_relaying,
  1419. dcc_relaying,
  1420. NULL,
  1421. NULL,
  1422. display_relaying,
  1423. kill_relay,
  1424. out_relay,
  1425. NULL
  1426. };
  1427. struct dcc_table DCC_FORK_RELAY =
  1428. {
  1429. "FORK_RELAY",
  1430. 0, /* Flags */
  1431. failed_tandem_relay,
  1432. cont_tandem_relay,
  1433. &connect_timeout,
  1434. failed_tandem_relay,
  1435. display_tandem_relay,
  1436. kill_relay,
  1437. NULL,
  1438. NULL
  1439. };
  1440. struct dcc_table DCC_PRE_RELAY =
  1441. {
  1442. "PRE_RELAY",
  1443. 0, /* Flags */
  1444. failed_pre_relay,
  1445. pre_relay,
  1446. NULL,
  1447. NULL,
  1448. display_pre_relay,
  1449. kill_relay,
  1450. NULL,
  1451. NULL
  1452. };
  1453. /* Once a minute, send 'ping' to each bot -- no exceptions
  1454. */
  1455. void check_botnet_pings()
  1456. {
  1457. int i, bots, users, top_index = 0;
  1458. tand_t *bot = NULL;
  1459. for (i = 0; i < dcc_total; i++) {
  1460. if (dcc[i].type) {
  1461. top_index = i;
  1462. if (dcc[i].type == &DCC_BOT) {
  1463. if (dcc[i].status & STAT_LEAF) {
  1464. tand_t *via = findbot(dcc[i].nick);
  1465. for (bot = tandbot; bot; bot = bot->next) {
  1466. if ((via == bot->via) && (bot != via)) {
  1467. /* Not leaflike behavior */
  1468. if (dcc[i].status & STAT_WARNED) {
  1469. char s[1024] = "";
  1470. putlog(LOG_BOTS, "*", "%s %s (%s).", "Disconnected from:", dcc[i].nick, "unleaflike behavior");
  1471. dprintf(i, "bye %s\n", "unleaflike behavior");
  1472. bot = findbot(dcc[i].nick);
  1473. bots = bots_in_subtree(bot);
  1474. users = users_in_subtree(bot);
  1475. simple_snprintf(s, sizeof(s), "%s %s (%s) (lost %d bot%s and %d user%s)",
  1476. "Disconnected from:", dcc[i].nick, "unleaflike behavior",
  1477. bots, (bots != 1) ? "s" : "", users, (users != 1) ?
  1478. "s" : "");
  1479. chatout("*** %s\n", s);
  1480. botnet_send_unlinked(i, dcc[i].nick, s);
  1481. killsock(dcc[i].sock);
  1482. lostdcc(i);
  1483. } else {
  1484. botnet_send_reject(i, conf.bot->nick, NULL, bot->bot, NULL, NULL);
  1485. dcc[i].status |= STAT_WARNED;
  1486. }
  1487. } else
  1488. dcc[i].status &= ~STAT_WARNED;
  1489. }
  1490. }
  1491. if (dcc[i].status & STAT_PINGED) {
  1492. char s[1024] = "";
  1493. putlog(LOG_BOTS, "*", "%s: %s", "Ping timeout", dcc[i].nick);
  1494. bot = findbot(dcc[i].nick);
  1495. bots = bots_in_subtree(bot);
  1496. users = users_in_subtree(bot);
  1497. simple_snprintf(s, sizeof(s), "%s: %s (lost %d bot%s and %d user%s)", "Ping timeout",
  1498. dcc[i].nick, bots, (bots != 1) ? "s" : "",
  1499. users, (users != 1) ? "s" : "");
  1500. chatout("*** %s\n", s);
  1501. botnet_send_unlinked(i, dcc[i].nick, s);
  1502. killsock(dcc[i].sock);
  1503. lostdcc(i);
  1504. } else {
  1505. botnet_send_ping(i);
  1506. dcc[i].status |= STAT_PINGED;
  1507. }
  1508. }
  1509. }
  1510. }
  1511. if (top_index != (dcc_total - 1))
  1512. dcc_total = top_index + 1;
  1513. }
  1514. void zapfbot(int idx)
  1515. {
  1516. char s[1024] = "";
  1517. tand_t *bot = findbot(dcc[idx].nick);
  1518. int bots = bots_in_subtree(bot), users = users_in_subtree(bot);
  1519. simple_snprintf(s, sizeof(s), "%s: %s (lost %d bot%s and %d user%s)", "Dropped bot",
  1520. dcc[idx].nick, bots, (bots != 1) ? "s" : "", users,
  1521. (users != 1) ? "s" : "");
  1522. chatout("*** %s\n", s);
  1523. botnet_send_unlinked(idx, dcc[idx].nick, s);
  1524. killsock(dcc[idx].sock);
  1525. lostdcc(idx);
  1526. }
  1527. static int get_role(char *bot)
  1528. {
  1529. struct userrec *u2 = NULL;
  1530. if (!(u2 = get_user_by_handle(userlist, bot)))
  1531. return 1;
  1532. if (bot_hublevel(u2) != 999)
  1533. return 0;
  1534. int rl, i;
  1535. struct bot_addr *ba = NULL;
  1536. int r[5] = { 0, 0, 0, 0, 0 };
  1537. struct userrec *u = NULL;
  1538. for (u = userlist; u; u = u->next) {
  1539. if (u->bot && bot_hublevel(u) == 999) {
  1540. if (strcmp(u->handle, bot)) {
  1541. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
  1542. if ((nextbot(u->handle) >= 0) && (ba) && (ba->roleid > 0) && (ba->roleid < 5))
  1543. r[(ba->roleid - 1)]++;
  1544. }
  1545. }
  1546. }
  1547. rl = 0;
  1548. for (i = 1; i <= 4; i++)
  1549. if (r[i] < r[rl])
  1550. rl = i;
  1551. rl++;
  1552. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u2);
  1553. if (ba)
  1554. ba->roleid = rl;
  1555. return rl;
  1556. }
  1557. void lower_bot_linked(int idx)
  1558. {
  1559. char tmp[6] = "";
  1560. simple_snprintf(tmp, sizeof(tmp), "rl %d", get_role(dcc[idx].nick));
  1561. putbot(dcc[idx].nick, tmp);
  1562. }