botnet.c 44 KB

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