botnet.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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. changeover_dcc(i, &DCC_FORK_BOT, sizeof(struct bot_info));
  974. dcc[i].timeval = now;
  975. struct bot_info dummy;
  976. strlcpy(dcc[i].u.bot->version, "(primitive bot)", sizeof(dummy.version));
  977. strlcpy(dcc[i].u.bot->sysname, "*", 2);
  978. strlcpy(dcc[i].u.bot->linker, linker, sizeof(dummy.linker));
  979. dcc[i].u.bot->numver = idx;
  980. free(linker);
  981. dcc[i].u.bot->port = dcc[i].port; /* Remember where i started */
  982. #ifdef USE_IPV6
  983. int af_type;
  984. if (dcc[i].port)
  985. af_type = is_dotted_ip(dcc[i].host);
  986. else
  987. af_type = AF_UNIX;
  988. dcc[i].sock = getsock(SOCK_STRONGCONN, af_type);
  989. #else
  990. dcc[i].sock = getsock(SOCK_STRONGCONN);
  991. #endif /* USE_IPV6 */
  992. // if (dcc[i].sock > 0)
  993. // identd_open(); /* will be closed when an ident is replied. */
  994. int open_telnet_return;
  995. if (dcc[i].sock < 0 || (open_telnet_return = open_telnet_raw(dcc[i].sock, dcc[i].host, dcc[i].port, 0, 1)) < 0) {
  996. if (open_telnet_return == -1)
  997. dcc[i].sock = -1;
  998. failed_link(i);
  999. } else { /* let's attempt to initiate SSL before ANYTHING else... */
  1000. dcc[i].ssl = 0;
  1001. }
  1002. /* wait for async reply */
  1003. }
  1004. static void failed_tandem_relay(int idx)
  1005. {
  1006. int uidx = (-1), i;
  1007. for (i = 0; i < dcc_total; i++) {
  1008. if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) &&
  1009. (dcc[i].u.relay->sock == dcc[idx].sock))
  1010. uidx = i;
  1011. }
  1012. if (uidx < 0) {
  1013. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1014. if (dcc[idx].sock != -1) {
  1015. killsock(dcc[idx].sock);
  1016. dcc[idx].sock = -1;
  1017. }
  1018. lostdcc(idx);
  1019. return;
  1020. }
  1021. struct chat_info *ci = dcc[uidx].u.relay->chat;
  1022. dprintf(uidx, "Could not relay to %s.\n", dcc[idx].nick);
  1023. dcc[uidx].status = dcc[uidx].u.relay->old_status;
  1024. free(dcc[uidx].u.relay);
  1025. dcc[uidx].u.chat = ci;
  1026. dcc[uidx].type = &DCC_CHAT;
  1027. if (dcc[idx].sock != -1) {
  1028. killsock(dcc[idx].sock);
  1029. dcc[idx].sock = -1;
  1030. }
  1031. lostdcc(idx);
  1032. return;
  1033. }
  1034. static void tandem_relay_dns_callback(int, void *, const char *, bd::Array<bd::String>);
  1035. /* Relay to another tandembot
  1036. */
  1037. void tandem_relay(int idx, char *nick, register int i)
  1038. {
  1039. struct userrec *u = get_user_by_handle(userlist, nick);
  1040. if (!u || !u->bot) {
  1041. dprintf(idx, "%s %s\n", nick, "is not a known bot.");
  1042. return;
  1043. }
  1044. if (!strcasecmp(nick, conf.bot->nick)) {
  1045. dprintf(idx, "%s\n", "Relay to myself? What on EARTH would be the point?!");
  1046. return;
  1047. }
  1048. /* Address to connect to is in 'info' */
  1049. struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
  1050. if (!bi || !strlen(bi->address) || !bi->relay_port || (bi->relay_port <= 0)) {
  1051. dprintf(idx, "Invalid telnet address:port stored for '%s'.\n", nick);
  1052. dprintf(idx, "Use: %schaddr %s <address>:<port#>[/<relay-port#>]\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "", nick);
  1053. return;
  1054. }
  1055. i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  1056. if (i < 0) {
  1057. dprintf(idx, "%s\n", "Sorry, too many DCC connections.");
  1058. return;
  1059. }
  1060. dcc[i].port = bi->relay_port;
  1061. dcc[i].addr = 0L;
  1062. strlcpy(dcc[i].nick, nick, NICKLEN);
  1063. dcc[i].user = u;
  1064. strlcpy(dcc[i].host, bi->address, UHOSTLEN);
  1065. if (conf.bot->hub)
  1066. dprintf(idx, "%s %s @ %s:%d ...\n", "Connecting to", nick, bi->address, bi->relay_port);
  1067. dprintf(idx, "(Type *BYE* on a line by itself to abort.)\n");
  1068. dcc[idx].type = &DCC_PRE_RELAY;
  1069. struct chat_info *ci = dcc[idx].u.chat;
  1070. dcc[idx].u.relay = (struct relay_info *) my_calloc(1, sizeof(struct relay_info));
  1071. dcc[idx].u.relay->chat = ci;
  1072. dcc[idx].u.relay->old_status = dcc[idx].status;
  1073. dcc[idx].u.relay->idx = i;
  1074. dcc[idx].u.relay->sock = -1;
  1075. dcc[i].timeval = now;
  1076. dcc[i].u.dns->ibuf = idx;
  1077. int dns_id = egg_dns_lookup(bi->address, 20, tandem_relay_dns_callback, (void *) (long) i);
  1078. if (dns_id >= 0)
  1079. dcc[i].dns_id = dns_id;
  1080. return;
  1081. /* wait for async reply */
  1082. }
  1083. static void tandem_relay_dns_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
  1084. {
  1085. //64bit hacks
  1086. long data = (long) client_data;
  1087. int i = (int) data, idx = -1;
  1088. if (!valid_dns_id(i, id))
  1089. return;
  1090. if (valid_idx(i))
  1091. idx = dcc[i].u.dns->ibuf;
  1092. if (idx < 0) {
  1093. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", i, idx);
  1094. lostdcc(i);
  1095. return;
  1096. }
  1097. if (!ips.size()) {
  1098. struct chat_info *ci = dcc[idx].u.relay->chat;
  1099. dprintf(idx, "Could not relay to %s.\n", dcc[i].nick);
  1100. dcc[idx].status = dcc[idx].u.relay->old_status;
  1101. free(dcc[idx].u.relay);
  1102. dcc[idx].u.chat = ci;
  1103. dcc[idx].type = &DCC_CHAT;
  1104. lostdcc(i);
  1105. return;
  1106. }
  1107. #ifdef USE_IPV6
  1108. int af = is_dotted_ip(bd::String(ips[0]).c_str());
  1109. dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, af);
  1110. #else
  1111. dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
  1112. #endif /* USE_IPV6 */
  1113. if (dcc[i].sock < 0) {
  1114. lostdcc(i);
  1115. dprintf(idx, "No free sockets available.\n");
  1116. return;
  1117. }
  1118. dcc[idx].u.relay->sock = dcc[i].sock;
  1119. changeover_dcc(i, &DCC_FORK_RELAY, sizeof(struct relay_info));
  1120. dcc[i].addr = inet_addr(bd::String(ips[0]).c_str());
  1121. dcc[i].u.relay->chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
  1122. dcc[i].u.relay->sock = dcc[idx].sock;
  1123. dcc[i].u.relay->port = dcc[i].port;
  1124. #ifdef USE_IPV6
  1125. dcc[i].u.relay->af = af;
  1126. #endif
  1127. dcc[i].u.relay->chat->away = NULL;
  1128. dcc[i].u.relay->chat->msgs_per_sec = 0;
  1129. dcc[i].u.relay->chat->con_flags = 0;
  1130. dcc[i].u.relay->chat->buffer = NULL;
  1131. dcc[i].u.relay->chat->max_line = 0;
  1132. dcc[i].u.relay->chat->line_count = 0;
  1133. dcc[i].u.relay->chat->current_lines = 0;
  1134. dcc[i].timeval = now;
  1135. if (open_telnet_raw(dcc[i].sock, bd::String(ips[0]).c_str(), dcc[i].port, 0) < 0) {
  1136. dcc[i].sock = -1;
  1137. failed_tandem_relay(i);
  1138. }
  1139. }
  1140. /* Input from user before connect is ready
  1141. */
  1142. static void pre_relay(int idx, char *buf, register int len)
  1143. {
  1144. register int tidx = (-1), i;
  1145. for (i = 0; i < dcc_total; i++) {
  1146. if (dcc[i].type && dcc[i].type == &DCC_FORK_RELAY && (dcc[i].u.relay->sock == dcc[idx].sock)) {
  1147. tidx = i;
  1148. break;
  1149. }
  1150. }
  1151. if (tidx < 0) {
  1152. /* Now try to find it among the DNSWAIT sockets instead. */
  1153. for (i = 0; i < dcc_total; i++) {
  1154. if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT && (dcc[idx].u.relay->idx == i))) {
  1155. tidx = i;
  1156. break;
  1157. }
  1158. }
  1159. }
  1160. if (tidx < 0) {
  1161. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1162. killsock(dcc[idx].sock);
  1163. lostdcc(idx);
  1164. return;
  1165. }
  1166. if (!strcasecmp(buf, "*bye*")) {
  1167. /* Disconnect */
  1168. struct chat_info *ci = dcc[idx].u.relay->chat;
  1169. dprintf(idx, "Aborting relay attempt to %s.\n", dcc[tidx].nick);
  1170. dprintf(idx, "You are now back on %s.\n\n", conf.bot->nick);
  1171. putlog(LOG_MISC, "*", "Relay aborted: %s -> %s", dcc[idx].nick, dcc[tidx].nick);
  1172. dcc[idx].status = dcc[idx].u.relay->old_status;
  1173. free(dcc[idx].u.relay);
  1174. dcc[idx].u.chat = ci;
  1175. dcc[idx].type = &DCC_CHAT;
  1176. if (dcc[tidx].sock != -1)
  1177. killsock(dcc[tidx].sock);
  1178. lostdcc(tidx);
  1179. return;
  1180. }
  1181. }
  1182. /* User disconnected before her relay had finished connecting
  1183. */
  1184. static void failed_pre_relay(int idx)
  1185. {
  1186. register int tidx = (-1), i;
  1187. for (i = 0; i < dcc_total; i++) {
  1188. if (dcc[i].type && (dcc[i].type == &DCC_FORK_RELAY) &&
  1189. (dcc[i].u.relay->sock == dcc[idx].sock)) {
  1190. tidx = i;
  1191. break;
  1192. }
  1193. }
  1194. if (tidx < 0) {
  1195. /* Now try to find it among the DNSWAIT sockets instead. */
  1196. for (i = 0; i < dcc_total; i++) {
  1197. if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT && (dcc[idx].u.relay->idx == i))) {
  1198. tidx = i;
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. if (tidx < 0) {
  1204. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1205. killsock(dcc[idx].sock);
  1206. lostdcc(idx);
  1207. return;
  1208. }
  1209. putlog(LOG_MISC, "*", "%s [%s]%s/%d", "Lost dcc connection to", dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  1210. putlog(LOG_MISC, "*", "(%s %s)", "Dropping relay attempt to", dcc[tidx].nick);
  1211. if ((dcc[tidx].sock != STDOUT) || backgrd) {
  1212. if (idx > tidx) {
  1213. int t = tidx;
  1214. tidx = idx;
  1215. idx = t;
  1216. }
  1217. if (dcc[tidx].sock != -1)
  1218. killsock(dcc[tidx].sock);
  1219. lostdcc(tidx);
  1220. } else {
  1221. fatal("Lost my terminal?!", 0);
  1222. }
  1223. if (dcc[idx].sock != -1)
  1224. killsock(dcc[idx].sock);
  1225. lostdcc(idx);
  1226. }
  1227. static void cont_tandem_relay(int idx, char *buf, register int len)
  1228. {
  1229. register int uidx = (-1), i;
  1230. struct relay_info *ri = NULL;
  1231. for (i = 0; i < dcc_total; i++) {
  1232. if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) && (dcc[i].u.relay->sock == dcc[idx].sock))
  1233. uidx = i;
  1234. }
  1235. if (uidx < 0) {
  1236. putlog(LOG_MISC, "*", "Can't find user for relay! %d -> %d", dcc[idx].sock, dcc[idx].u.relay->sock);
  1237. killsock(dcc[idx].sock);
  1238. lostdcc(idx);
  1239. return;
  1240. }
  1241. dcc[idx].type = &DCC_RELAY;
  1242. dcc[idx].u.relay->sock = dcc[uidx].sock;
  1243. dcc[uidx].u.relay->sock = dcc[idx].sock;
  1244. dprintf(uidx, "%s %s ...\n", "Success!\n\nNOW CONNECTED TO RELAY BOT", dcc[idx].nick);
  1245. dprintf(uidx, "(You can type *BYE* to prematurely close the connection.)\n\n");
  1246. putlog(LOG_MISC, "*", "%s %s -> %s", "Relay link:",
  1247. dcc[uidx].nick, dcc[idx].nick);
  1248. ri = dcc[uidx].u.relay;
  1249. dcc[uidx].type = &DCC_CHAT;
  1250. dcc[uidx].u.chat = ri->chat;
  1251. if (dcc[uidx].u.chat->channel >= 0) {
  1252. chanout_but(-1, dcc[uidx].u.chat->channel, "*** %s left the party line.\n", dcc[uidx].nick);
  1253. if (dcc[uidx].u.chat->channel < GLOBAL_CHANS)
  1254. botnet_send_part_idx(uidx, NULL);
  1255. }
  1256. check_bind_chof(dcc[uidx].nick, uidx);
  1257. dcc[uidx].type = &DCC_RELAYING;
  1258. dcc[uidx].u.relay = ri;
  1259. }
  1260. static void eof_dcc_relay(int idx)
  1261. {
  1262. register int j;
  1263. for (j = 0; j < dcc_total; j++)
  1264. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock)
  1265. break;
  1266. if (j == dcc_total || !dcc[j].type) {
  1267. killsock(dcc[idx].sock);
  1268. lostdcc(idx);
  1269. return;
  1270. }
  1271. dcc[j].status = dcc[j].u.relay->old_status;
  1272. /* In case echo was off, turn it back on (send IAC WON'T ECHO): */
  1273. if (dcc[j].status & STAT_TELNET)
  1274. dprintf(j, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  1275. putlog(LOG_MISC, "*", "%s: %s -> %s", "Ended relay link", dcc[j].nick,
  1276. dcc[idx].nick);
  1277. dprintf(j, "\n\n*** %s %s\n", "RELAY CONNECTION DROPPED.\nYou are now back on", conf.bot->nick);
  1278. struct chat_info *ci = dcc[j].u.relay->chat;
  1279. free(dcc[j].u.relay);
  1280. dcc[j].u.chat = ci;
  1281. dcc[j].type = &DCC_CHAT;
  1282. if (dcc[j].u.chat->channel >= 0) {
  1283. chanout_but(-1, dcc[j].u.chat->channel, "*** %s %s.\n",
  1284. dcc[j].nick, "rejoined the party line.");
  1285. if (dcc[j].u.chat->channel < GLOBAL_CHANS)
  1286. botnet_send_join_idx(j);
  1287. }
  1288. check_bind_chon(dcc[j].nick, j);
  1289. killsock(dcc[idx].sock);
  1290. lostdcc(idx);
  1291. }
  1292. static void eof_dcc_relaying(int idx)
  1293. {
  1294. register int j, x = dcc[idx].u.relay->sock;
  1295. putlog(LOG_MISC, "*", "%s [%s]%s/%d", "Lost dcc connection to", dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  1296. killsock(dcc[idx].sock);
  1297. lostdcc(idx);
  1298. for (j = 0; j < dcc_total; j++)
  1299. if (dcc[j].type && dcc[j].sock == x && dcc[j].type != &DCC_FORK_RELAY)
  1300. break;
  1301. putlog(LOG_MISC, "*", "(%s %s)", "Dropping relay link to", dcc[j].nick);
  1302. killsock(dcc[j].sock);
  1303. lostdcc(j); /* Drop connection to the bot */
  1304. }
  1305. static void dcc_relay(int idx, char *buf, int j)
  1306. {
  1307. unsigned char *p = (unsigned char *) buf;
  1308. int mark;
  1309. for (j = 0; j < dcc_total; j++)
  1310. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAYING)
  1311. break;
  1312. /* If redirecting to a non-telnet user, swallow telnet codes and
  1313. escape sequences. */
  1314. if (!(dcc[j].status & STAT_TELNET)) {
  1315. while (*p != 0) {
  1316. while (*p && *p != 255 && *p != '\r')
  1317. p++; /* Search for IAC, escape sequences and CR. */
  1318. if (*p == 255) {
  1319. mark = 2;
  1320. if (!*(p + 1))
  1321. mark = 1; /* Bogus */
  1322. if ((*(p + 1) >= 251) || (*(p + 1) <= 254)) {
  1323. mark = 3;
  1324. if (!*(p + 2))
  1325. mark = 2; /* Bogus */
  1326. }
  1327. strcpy((char *) p, (char *) (p + mark));
  1328. } else if (*p == '\r')
  1329. strcpy((char *) p, (char *) (p + 1));
  1330. }
  1331. if (!buf[0])
  1332. dprintf(-dcc[idx].u.relay->sock, " \n");
  1333. else
  1334. dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
  1335. return;
  1336. }
  1337. /* Telnet user */
  1338. if (!buf[0])
  1339. dprintf(-dcc[idx].u.relay->sock, " \r\n");
  1340. else
  1341. dprintf(-dcc[idx].u.relay->sock, "%s\r\n", buf);
  1342. }
  1343. static void dcc_relaying(int idx, char *buf, int j)
  1344. {
  1345. if (strcasecmp(buf, "*bye*")) {
  1346. dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
  1347. return;
  1348. }
  1349. /* The user want's to abort, so return them to partyline */
  1350. for (j = 0; j < dcc_total; j++)
  1351. if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAY)
  1352. break;
  1353. dcc[idx].status = dcc[idx].u.relay->old_status;
  1354. /* In case echo was off, turn it back on (send IAC WON'T ECHO): */
  1355. if (dcc[idx].status & STAT_TELNET)
  1356. dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  1357. dprintf(idx, "\n(%s %s.)\n", "Breaking connection to", dcc[j].nick);
  1358. dprintf(idx, "You are now back on %s.\n\n", conf.bot->nick);
  1359. putlog(LOG_MISC, "*", "%s: %s -> %s", "Relay broken", dcc[idx].nick, dcc[j].nick);
  1360. if (dcc[idx].u.relay->chat->channel >= 0) {
  1361. chanout_but(-1, dcc[idx].u.relay->chat->channel, "*** %s joined the party line.\n", dcc[idx].nick);
  1362. if (dcc[idx].u.relay->chat->channel < GLOBAL_CHANS)
  1363. botnet_send_join_idx(idx);
  1364. }
  1365. struct chat_info *ci = dcc[idx].u.relay->chat;
  1366. free(dcc[idx].u.relay);
  1367. dcc[idx].u.chat = ci;
  1368. dcc[idx].type = &DCC_CHAT;
  1369. check_bind_chon(dcc[idx].nick, idx);
  1370. if (dcc[j].sock != -1)
  1371. killsock(dcc[j].sock);
  1372. lostdcc(j);
  1373. }
  1374. static void display_relay(int i, char *other, size_t bufsiz)
  1375. {
  1376. simple_snprintf(other, bufsiz, "rela -> sock %d", dcc[i].u.relay->sock);
  1377. }
  1378. static void display_relaying(int i, char *other, size_t bufsiz)
  1379. {
  1380. simple_snprintf(other, bufsiz, ">rly -> sock %d", dcc[i].u.relay->sock);
  1381. }
  1382. static void display_tandem_relay(int i, char *other, size_t bufsiz)
  1383. {
  1384. strlcpy(other, "other rela", bufsiz);
  1385. }
  1386. static void display_pre_relay(int i, char *other, size_t bufsiz)
  1387. {
  1388. strlcpy(other, "other >rly", bufsiz);
  1389. }
  1390. static void kill_relay(int idx, void *x)
  1391. {
  1392. register struct relay_info *p = (struct relay_info *) x;
  1393. if (p->chat)
  1394. DCC_CHAT.kill(idx, p->chat);
  1395. free(p);
  1396. }
  1397. struct dcc_table DCC_RELAY =
  1398. {
  1399. "RELAY",
  1400. 0, /* Flags */
  1401. eof_dcc_relay,
  1402. dcc_relay,
  1403. NULL,
  1404. NULL,
  1405. display_relay,
  1406. kill_relay,
  1407. NULL,
  1408. NULL
  1409. };
  1410. static void out_relay(int idx, char *buf, void *x)
  1411. {
  1412. register struct relay_info *p = (struct relay_info *) x;
  1413. if (p && p->chat)
  1414. DCC_CHAT.output(idx, buf, p->chat);
  1415. else
  1416. tputs(dcc[idx].sock, buf, strlen(buf));
  1417. }
  1418. struct dcc_table DCC_RELAYING =
  1419. {
  1420. "RELAYING",
  1421. 0, /* Flags */
  1422. eof_dcc_relaying,
  1423. dcc_relaying,
  1424. NULL,
  1425. NULL,
  1426. display_relaying,
  1427. kill_relay,
  1428. out_relay,
  1429. NULL
  1430. };
  1431. struct dcc_table DCC_FORK_RELAY =
  1432. {
  1433. "FORK_RELAY",
  1434. 0, /* Flags */
  1435. failed_tandem_relay,
  1436. cont_tandem_relay,
  1437. &connect_timeout,
  1438. failed_tandem_relay,
  1439. display_tandem_relay,
  1440. kill_relay,
  1441. NULL,
  1442. NULL
  1443. };
  1444. struct dcc_table DCC_PRE_RELAY =
  1445. {
  1446. "PRE_RELAY",
  1447. 0, /* Flags */
  1448. failed_pre_relay,
  1449. pre_relay,
  1450. NULL,
  1451. NULL,
  1452. display_pre_relay,
  1453. kill_relay,
  1454. NULL,
  1455. NULL
  1456. };
  1457. /* Once a minute, send 'ping' to each bot -- no exceptions
  1458. */
  1459. void check_botnet_pings()
  1460. {
  1461. int i, bots, users, top_index = 0;
  1462. tand_t *bot = NULL;
  1463. for (i = 0; i < dcc_total; i++) {
  1464. if (dcc[i].type) {
  1465. top_index = i;
  1466. if (dcc[i].type == &DCC_BOT) {
  1467. // Hubs only allow localhubs to link, which CAN link bots now, so this isn't so cut and dry now
  1468. #ifdef no
  1469. if (dcc[i].status & STAT_LEAF) {
  1470. tand_t *via = findbot(dcc[i].nick);
  1471. // Check if this leaf has any linked bots
  1472. for (bot = tandbot; bot; bot = bot->next) {
  1473. if ((via == bot->via) && (bot != via)) {
  1474. /* Not leaflike behavior */
  1475. if (dcc[i].status & STAT_WARNED) {
  1476. char s[1024] = "";
  1477. putlog(LOG_BOTS, "*", "%s %s (%s).", "Disconnected from:", dcc[i].nick, "unleaflike behavior");
  1478. dprintf(i, "bye %s\n", "unleaflike behavior");
  1479. bot = findbot(dcc[i].nick);
  1480. bots = bots_in_subtree(bot);
  1481. users = users_in_subtree(bot);
  1482. simple_snprintf(s, sizeof(s), "%s %s (%s) (lost %d bot%s and %d user%s)",
  1483. "Disconnected from:", dcc[i].nick, "unleaflike behavior",
  1484. bots, (bots != 1) ? "s" : "", users, (users != 1) ?
  1485. "s" : "");
  1486. chatout("*** %s\n", s);
  1487. botnet_send_unlinked(i, dcc[i].nick, s);
  1488. killsock(dcc[i].sock);
  1489. lostdcc(i);
  1490. } else {
  1491. botnet_send_reject(i, conf.bot->nick, NULL, bot->bot, NULL, NULL);
  1492. dcc[i].status |= STAT_WARNED;
  1493. }
  1494. } else
  1495. dcc[i].status &= ~STAT_WARNED;
  1496. }
  1497. }
  1498. #endif
  1499. if (dcc[i].status & STAT_PINGED) {
  1500. char s[1024] = "";
  1501. putlog(LOG_BOTS, "*", "%s: %s", "Ping timeout", dcc[i].nick);
  1502. bot = findbot(dcc[i].nick);
  1503. bots = bots_in_subtree(bot);
  1504. users = users_in_subtree(bot);
  1505. simple_snprintf(s, sizeof(s), "%s: %s (lost %d bot%s and %d user%s)", "Ping timeout",
  1506. dcc[i].nick, bots, (bots != 1) ? "s" : "",
  1507. users, (users != 1) ? "s" : "");
  1508. chatout("*** %s\n", s);
  1509. botnet_send_unlinked(i, dcc[i].nick, s);
  1510. killsock(dcc[i].sock);
  1511. lostdcc(i);
  1512. } else {
  1513. botnet_send_ping(i);
  1514. dcc[i].status |= STAT_PINGED;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. if (top_index != (dcc_total - 1))
  1520. dcc_total = top_index + 1;
  1521. }
  1522. void zapfbot(int idx)
  1523. {
  1524. char s[1024] = "";
  1525. tand_t *bot = findbot(dcc[idx].nick);
  1526. int bots = bots_in_subtree(bot), users = users_in_subtree(bot);
  1527. simple_snprintf(s, sizeof(s), "%s: %s (lost %d bot%s and %d user%s)", "Dropped bot",
  1528. dcc[idx].nick, bots, (bots != 1) ? "s" : "", users,
  1529. (users != 1) ? "s" : "");
  1530. chatout("*** %s\n", s);
  1531. botnet_send_unlinked(idx, dcc[idx].nick, s);
  1532. killsock(dcc[idx].sock);
  1533. lostdcc(idx);
  1534. }
  1535. static int get_role(char *bot)
  1536. {
  1537. struct userrec *u2 = NULL;
  1538. if (!(u2 = get_user_by_handle(userlist, bot)))
  1539. return 1;
  1540. if (bot_hublevel(u2) != 999)
  1541. return 0;
  1542. int rl, i;
  1543. struct bot_addr *ba = NULL;
  1544. int r[5] = { 0, 0, 0, 0, 0 };
  1545. struct userrec *u = NULL;
  1546. for (u = userlist; u; u = u->next) {
  1547. if (u->bot && bot_hublevel(u) == 999) {
  1548. if (strcmp(u->handle, bot)) {
  1549. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
  1550. if ((nextbot(u->handle) >= 0) && (ba) && (ba->roleid > 0) && (ba->roleid < 5))
  1551. r[(ba->roleid - 1)]++;
  1552. }
  1553. }
  1554. }
  1555. rl = 0;
  1556. for (i = 1; i <= 4; i++)
  1557. if (r[i] < r[rl])
  1558. rl = i;
  1559. rl++;
  1560. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u2);
  1561. if (ba)
  1562. ba->roleid = rl;
  1563. return rl;
  1564. }
  1565. void lower_bot_linked(int idx)
  1566. {
  1567. char tmp[6] = "";
  1568. simple_snprintf(tmp, sizeof(tmp), "rl %d", get_role(dcc[idx].nick));
  1569. putbot(dcc[idx].nick, tmp);
  1570. }