botnet.c 48 KB

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