1
0

users.cc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2014 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. * users.c -- handles:
  22. * testing and enforcing ignores
  23. * adding and removing ignores
  24. * listing ignores
  25. * auto-linking bots
  26. * sending and receiving a userfile from a bot
  27. * listing users ('.whois' and '.match')
  28. * reading the user file
  29. *
  30. * dprintf'ized, 9nov1995
  31. *
  32. */
  33. #include "common.h"
  34. #include "users.h"
  35. #include "rfc1459.h"
  36. #include "src/mod/share.mod/share.h"
  37. #include "dcc.h"
  38. #include "settings.h"
  39. #include "userrec.h"
  40. #include "misc.h"
  41. #include "set.h"
  42. #include "match.h"
  43. #include "main.h"
  44. #include "chanprog.h"
  45. #include "dccutil.h"
  46. #include "crypt.h"
  47. #include "botnet.h"
  48. #include "chan.h"
  49. #include "tandem.h"
  50. #include "src/mod/channels.mod/channels.h"
  51. #include <netinet/in.h>
  52. #include <arpa/inet.h>
  53. #include "misc_file.h"
  54. #include "EncryptedStream.h"
  55. char userfile[PATH_MAX] = ""; /* where the user records are stored */
  56. char autolink_failed[HANDLEN + 1] = "";
  57. interval_t ignore_time = 10; /* how many minutes will ignores last? */
  58. bool dont_restructure = 0; /* set when we botlink() to a hub with +U, only stops bot from restructuring */
  59. /* is this nick!user@host being ignored? */
  60. bool
  61. match_ignore(const char *uhost)
  62. {
  63. for (struct igrec *ir = global_ign; ir; ir = ir->next)
  64. if (wild_match(ir->igmask, uhost))
  65. return 1;
  66. return 0;
  67. }
  68. int equals_ignore(char *uhost)
  69. {
  70. struct igrec *u = global_ign;
  71. for (; u; u = u->next)
  72. if (!rfc_casecmp(u->igmask, uhost)) {
  73. if (u->flags & IGREC_PERM)
  74. return 2;
  75. else
  76. return 1;
  77. }
  78. return 0;
  79. }
  80. char *delignore(char *ign)
  81. {
  82. int i = 0, j;
  83. struct igrec **u = NULL, *t = NULL;
  84. static char temp[256] = "";
  85. if (!strchr(ign, '!') && (j = atoi(ign))) {
  86. for (u = &global_ign, j--; *u && j; u = &((*u)->next), j--)
  87. ;
  88. if (*u) {
  89. strlcpy(temp, (*u)->igmask, sizeof temp);
  90. i = 1;
  91. }
  92. } else {
  93. /* find the matching host, if there is one */
  94. for (u = &global_ign; *u && !i; u = &((*u)->next))
  95. if (!rfc_casecmp(ign, (*u)->igmask)) {
  96. strlcpy(temp, ign, sizeof temp);
  97. i = 1;
  98. break;
  99. }
  100. }
  101. if (i) {
  102. if (!noshare) {
  103. char *mask = str_escape(temp, ':', '\\');
  104. if (mask) {
  105. shareout("-i %s\n", mask);
  106. free(mask);
  107. }
  108. }
  109. free((*u)->igmask);
  110. free((*u)->msg);
  111. free((*u)->user);
  112. t = *u;
  113. *u = (*u)->next;
  114. free(t);
  115. } else
  116. temp[0] = 0;
  117. return temp;
  118. }
  119. void addignore(char *ign, char *from, const char *mnote, time_t expire_time)
  120. {
  121. struct igrec *p = NULL, *l = NULL;
  122. for (l = global_ign; l; l = l->next)
  123. if (!rfc_casecmp(l->igmask, ign)) {
  124. p = l;
  125. break;
  126. }
  127. if (p == NULL) {
  128. p = (struct igrec *) calloc(1, sizeof(struct igrec));
  129. p->next = global_ign;
  130. global_ign = p;
  131. } else {
  132. free(p->igmask);
  133. free(p->user);
  134. free(p->msg);
  135. }
  136. p->expire = expire_time;
  137. p->added = now;
  138. p->flags = expire_time ? 0 : IGREC_PERM;
  139. p->igmask = strdup(ign);
  140. p->user = strdup(from);
  141. p->msg = strdup(mnote);
  142. if (!noshare) {
  143. char *mask = str_escape(ign, ':', '\\');
  144. if (mask) {
  145. shareout("+i %s %d %c %s %s\n", mask, (int) (expire_time - now), (p->flags & IGREC_PERM) ? 'p' : '-', from, mnote);
  146. free(mask);
  147. }
  148. }
  149. }
  150. /* take host entry from ignore list and display it ignore-style */
  151. void display_ignore(int idx, int number, struct igrec *ignore)
  152. {
  153. char dates[81] = "", s[41] = "";
  154. if (ignore->added) {
  155. daysago(now, ignore->added, s, sizeof(s));
  156. simple_snprintf(dates, sizeof(dates), "Started %s", s);
  157. }
  158. if (ignore->flags & IGREC_PERM)
  159. strlcpy(s, "(perm)", sizeof(s));
  160. else {
  161. char s1[41] = "";
  162. days(ignore->expire, now, s1, sizeof(s1));
  163. simple_snprintf(s, sizeof(s), "(expires %s)", s1);
  164. }
  165. if (number >= 0)
  166. dprintf(idx, " [%3d] %s %s\n", number, ignore->igmask, s);
  167. else
  168. dprintf(idx, "IGNORE: %s %s\n", ignore->igmask, s);
  169. if (ignore->msg && ignore->msg[0])
  170. dprintf(idx, " %s: %s\n", ignore->user, ignore->msg);
  171. else
  172. dprintf(idx, " placed by %s\n", ignore->user);
  173. if (dates[0])
  174. dprintf(idx, " %s\n", dates);
  175. }
  176. /* list the ignores and how long they've been active */
  177. void tell_ignores(int idx, char *match)
  178. {
  179. struct igrec *u = global_ign;
  180. if (u == NULL) {
  181. dprintf(idx, "No ignores.\n");
  182. return;
  183. }
  184. dprintf(idx, "%s:\n", "Currently ignoring");
  185. int k = 1;
  186. for (; u; u = u->next) {
  187. if (match[0]) {
  188. if (wild_match(match, u->igmask) ||
  189. wild_match(match, u->msg) ||
  190. wild_match(match, u->user))
  191. display_ignore(idx, k, u);
  192. k++;
  193. } else
  194. display_ignore(idx, k++, u);
  195. }
  196. }
  197. /* check for expired timed-ignores */
  198. void check_expired_ignores()
  199. {
  200. struct igrec **u = &global_ign;
  201. if (!*u)
  202. return;
  203. while (*u) {
  204. if (!((*u)->flags & IGREC_PERM) && (now >= (*u)->expire)) {
  205. putlog(LOG_MISC, "*", "%s %s (expired)", "No longer ignoring", (*u)->igmask);
  206. delignore((*u)->igmask);
  207. } else {
  208. u = &((*u)->next);
  209. }
  210. }
  211. }
  212. /* Channel mask loaded from user file. This function is
  213. * add(ban|invite|exempt)_fully merged into one. <cybah>
  214. */
  215. static void addmask_fully(struct chanset_t *chan, maskrec **m, maskrec **global,
  216. char *mask, char *from,
  217. char *note, time_t expire_time, int flags,
  218. time_t added, time_t last)
  219. {
  220. maskrec *p = (maskrec *) calloc(1, sizeof(maskrec));
  221. maskrec **u = (chan) ? m : global;
  222. p->next = *u;
  223. *u = p;
  224. p->expire = expire_time;
  225. p->added = added;
  226. p->lastactive = last;
  227. p->flags = flags;
  228. p->mask = strdup(mask);
  229. p->user = strdup(from);
  230. p->desc = strdup(note);
  231. }
  232. static void restore_chanmask(const char type, struct chanset_t *chan, char *host)
  233. {
  234. char *expi = NULL, *add = NULL, *last = NULL, *user = NULL, *desc = NULL;
  235. int flags = 0;
  236. maskrec **chan_masks = NULL, **global_masks = NULL;
  237. const char *str_type = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  238. if (type == 'b') {
  239. if (chan) chan_masks = &chan->bans;
  240. global_masks = &global_bans;
  241. } else if (type == 'e') {
  242. if (chan) chan_masks = &chan->exempts;
  243. global_masks = &global_exempts;
  244. } else if (type == 'I') {
  245. if (chan) chan_masks = &chan->invites;
  246. global_masks = &global_invites;
  247. }
  248. expi = strchr_unescape(host, ':', '\\');
  249. if (expi) {
  250. if (*expi == '+') {
  251. flags |= MASKREC_PERM;
  252. expi++;
  253. }
  254. add = strchr(expi, ':');
  255. if (add) {
  256. if (add[-1] == '*') {
  257. flags |= MASKREC_STICKY;
  258. add[-1] = 0;
  259. } else
  260. *add = 0;
  261. add++;
  262. if (*add == '+') {
  263. last = strchr(add, ':');
  264. if (last) {
  265. *last = 0;
  266. last++;
  267. user = strchr(last, ':');
  268. if (user) {
  269. *user = 0;
  270. user++;
  271. desc = strchr(user, ':');
  272. if (desc) {
  273. *desc = 0;
  274. desc++;
  275. addmask_fully(chan, chan_masks, global_masks, host, user,
  276. desc, atoi(expi), flags, atoi(add), atoi(last));
  277. return;
  278. }
  279. }
  280. }
  281. } else {
  282. desc = strchr(add, ':');
  283. if (desc) {
  284. *desc = 0;
  285. desc++;
  286. addmask_fully(chan, chan_masks, global_masks, host, add, desc,
  287. atoi(expi), flags, now, 0);
  288. return;
  289. }
  290. }
  291. }
  292. }
  293. putlog(LOG_MISC, "*", "*** Malformed %sline for %s%s%s.", str_type, chan ? chan->dname : "global_", chan ? "" : str_type, chan ? "" : "s");
  294. }
  295. static void restore_ignore(char *host)
  296. {
  297. char *expi = NULL, *user = NULL, *added = NULL, *desc = NULL;
  298. int flags = 0;
  299. struct igrec *p = NULL;
  300. expi = strchr_unescape(host, ':', '\\');
  301. if (expi) {
  302. if (*expi == '+') {
  303. flags |= IGREC_PERM;
  304. expi++;
  305. }
  306. user = strchr(expi, ':');
  307. if (user) {
  308. *user = 0;
  309. user++;
  310. added = strchr(user, ':');
  311. if (added) {
  312. *added = 0;
  313. added++;
  314. desc = strchr(added, ':');
  315. if (desc) {
  316. *desc = 0;
  317. desc++;
  318. }
  319. }
  320. p = (struct igrec *) calloc(1, sizeof(struct igrec));
  321. p->next = global_ign;
  322. global_ign = p;
  323. p->expire = atoi(expi);
  324. p->added = added ? atoi(added) : 0;
  325. p->flags = flags;
  326. p->igmask = strdup(host);
  327. p->user = strdup(user);
  328. if (desc) {
  329. p->msg = strdup(desc);
  330. } else
  331. p->msg = NULL;
  332. return;
  333. }
  334. }
  335. putlog(LOG_MISC, "*", "*** Malformed ignore line.");
  336. }
  337. static void
  338. tell_user(int idx, struct userrec *u)
  339. {
  340. char s[81] = "", s1[81] = "", format[81] = "";
  341. time_t now2;
  342. struct chanuserrec *ch = NULL;
  343. struct chanset_t *chan = NULL;
  344. struct user_entry *ue = NULL;
  345. struct laston_info *li = (struct laston_info *) get_user(&USERENTRY_LASTON, u);
  346. struct flag_record fr = {FR_GLOBAL, u->flags, 0, 0 };
  347. build_flags(s, &fr, NULL);
  348. if (!li || !li->laston)
  349. strlcpy(s1, "never", sizeof(s1));
  350. else {
  351. now2 = now - li->laston;
  352. if (now2 > 86400)
  353. strftime(s1, 7, "%d %b", gmtime(&li->laston));
  354. else
  355. strftime(s1, 6, "%H:%M", gmtime(&li->laston));
  356. }
  357. if (!u->bot) {
  358. simple_snprintf(format, sizeof format, "%%-%us %%-4s %%-15s %%s (%%-10.10s)\n", HANDLEN);
  359. dprintf(idx, format, u->handle, get_user(&USERENTRY_PASS, u) ? "yes" : "no", s, s1, (li && li->lastonplace) ? li->lastonplace : "nowhere");
  360. } else { /* BOT */
  361. simple_snprintf(format, sizeof format, "%%-%us %%-8s %%s (%%-10.10s)\n", HANDLEN);
  362. dprintf(idx, format, u->handle, s, s1, (li && li->lastonplace) ? li->lastonplace : "nowhere");
  363. }
  364. /* channel flags? */
  365. for (ch = u->chanrec; ch; ch = ch->next) {
  366. fr.match = FR_CHAN | FR_GLOBAL;
  367. chan = findchan_by_dname(ch->channel);
  368. get_user_flagrec(dcc[idx].user, &fr, ch->channel);
  369. if (!channel_privchan(chan) || (channel_privchan(chan) && (chan_op(fr) || glob_owner(fr)))) {
  370. if (glob_op(fr) || chan_op(fr)) {
  371. if (ch->laston == 0L)
  372. strlcpy(s1, "never", sizeof(s1));
  373. else {
  374. now2 = now - (ch->laston);
  375. if (now2 > 86400)
  376. strftime(s1, 7, "%d %b", gmtime(&ch->laston));
  377. else
  378. strftime(s1, 6, "%H:%M", gmtime(&ch->laston));
  379. }
  380. fr.match = FR_CHAN;
  381. fr.chan = ch->flags;
  382. build_flags(s, &fr, NULL);
  383. simple_snprintf(format, sizeof format, "%%%us %%-18s %%-15s %%s\n", HANDLEN-9);
  384. dprintf(idx, format, " ", ch->channel, s, s1);
  385. if (ch->info != NULL)
  386. dprintf(idx, " INFO: %s\n", ch->info);
  387. }
  388. }
  389. }
  390. /* user-defined extra fields */
  391. for (ue = u->entries; ue; ue = ue->next)
  392. if (!ue->name && ue->type->display)
  393. ue->type->display(idx, ue, u);
  394. }
  395. /* show user by ident */
  396. void tell_user_ident(int idx, char *id)
  397. {
  398. struct userrec *u = get_user_by_handle(userlist, id);
  399. struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  400. get_user_flagrec(dcc[idx].user, &user, NULL);
  401. if (u == NULL)
  402. u = get_user_by_host(id);
  403. if (u == NULL || (u && !whois_access(dcc[idx].user, u))) {
  404. dprintf(idx, "Can't find anyone matching that, or you have no access to view them.\n");
  405. return;
  406. }
  407. char format[81] = "";
  408. if (u->bot) {
  409. simple_snprintf(format, sizeof format, "%%-%us FLAGS LAST\n", HANDLEN);
  410. dprintf(idx, format, "BOTNICK");
  411. } else {
  412. simple_snprintf(format, sizeof format, "%%-%us PASS FLAGS LAST\n", HANDLEN);
  413. dprintf(idx, format, "HANDLE");
  414. }
  415. tell_user(idx, u);
  416. }
  417. /* match string:
  418. * wildcard to match nickname or hostmasks
  419. * +attr to find all with attr */
  420. void tell_users_match(int idx, char *mtch, int start, int limit,
  421. const char *chname, int isbot)
  422. {
  423. char format[81] = "";
  424. struct userrec *u = NULL;
  425. int fnd = 0, cnt = 0, nomns = 0, flags = 0;
  426. struct list_type *q = NULL;
  427. struct flag_record user, pls, mns;
  428. dprintf(idx, "*** Matching '%s':\n", mtch);
  429. if (isbot) {
  430. simple_snprintf(format, sizeof format, "%%-%us FLAGS LAST\n", HANDLEN);
  431. dprintf(idx, format, "BOTNICK");
  432. } else {
  433. simple_snprintf(format, sizeof format, "%%-%us PASS FLAGS LAST\n", HANDLEN);
  434. dprintf(idx, format, "HANDLE");
  435. }
  436. if (start > 1)
  437. dprintf(idx, "(skipping first %d)\n", start - 1);
  438. if (strchr("+-&|", *mtch)) {
  439. user.match = pls.match = FR_GLOBAL | FR_CHAN;
  440. if (isbot) {
  441. user.match |= FR_BOT;
  442. pls.match |= FR_BOT;
  443. }
  444. break_down_flags(mtch, &pls, &mns);
  445. mns.match = pls.match ^ (FR_AND | FR_OR);
  446. if (!mns.global && !mns.chan) {
  447. nomns = 1;
  448. if (!pls.global && !pls.chan) {
  449. /* happy now BB you weenie :P */
  450. dprintf(idx, "Unknown flag specified for matching!!\n");
  451. return;
  452. }
  453. }
  454. if (!chname || !chname[0])
  455. chname = dcc[idx].u.chat->con_chan;
  456. flags = 1;
  457. }
  458. for (u = userlist; u; u = u->next) {
  459. if (!whois_access(dcc[idx].user, u) || (isbot && !u->bot) || (!isbot && u->bot)) {
  460. continue;
  461. } else if (flags) {
  462. get_user_flagrec(u, &user, chname);
  463. if (flagrec_eq(&pls, &user)) {
  464. if (nomns || !flagrec_eq(&mns, &user)) {
  465. cnt++;
  466. if ((cnt <= limit) && (cnt >= start))
  467. tell_user(idx, u);
  468. if (cnt == limit + 1)
  469. dprintf(idx, "(more than %d matches; list truncated)\n", limit);
  470. }
  471. }
  472. } else if (wild_match(mtch, u->handle)) {
  473. cnt++;
  474. if ((cnt <= limit) && (cnt >= start))
  475. tell_user(idx, u);
  476. if (cnt == limit + 1)
  477. dprintf(idx, "(more than %d matches; list truncated)\n", limit);
  478. } else {
  479. fnd = 0;
  480. for (q = (struct list_type *) get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
  481. if ((wild_match(mtch, q->extra)) && (!fnd)) {
  482. cnt++;
  483. fnd = 1;
  484. if ((cnt <= limit) && (cnt >= start)) {
  485. tell_user(idx, u);
  486. }
  487. if (cnt == limit + 1)
  488. dprintf(idx, "(more than %d matches; list truncated)\n", limit);
  489. }
  490. }
  491. }
  492. }
  493. dprintf(idx, "--- Found %d match%s.\n", cnt, cnt == 1 ? "" : "es");
  494. }
  495. void backup_userfile()
  496. {
  497. char s[DIRMAX] = "", s2[DIRMAX] = "";
  498. putlog(LOG_MISC, "*", "Backing up user file...");
  499. simple_snprintf(s, sizeof s, "%s/.u.0", conf.datadir);
  500. simple_snprintf(s2, sizeof s2, "%s/.u.1", conf.datadir);
  501. movefile(s, s2);
  502. copyfile(userfile, s);
  503. }
  504. /*
  505. * tagged lines in the user file:
  506. * * OLD:
  507. * # (comment)
  508. * ; (comment)
  509. * - hostmask(s)
  510. * + email
  511. * * dcc directory
  512. * = comment
  513. * : info line
  514. * . xtra (Tcl)
  515. * ! channel-specific
  516. * !! global laston
  517. * :: channel-specific bans
  518. * NEW:
  519. * *ban global bans
  520. * *ignore global ignores
  521. * ::#chan channel bans
  522. * - entries in each
  523. * + denotes tcl command
  524. * <handle> begin user entry
  525. * --KEY INFO - info on each
  526. * NEWER:
  527. * % exemptmask(s)
  528. * @ Invitemask(s)
  529. * *exempt global exempts
  530. * *Invite global Invites
  531. * && channel-specific exempts
  532. * &&#chan channel exempts
  533. * $$ channel-specific Invites
  534. * $$#chan channel Invites
  535. */
  536. int readuserfile(const char *file, struct userrec **ret)
  537. {
  538. const char salt1[] = SALT1;
  539. EncryptedStream stream(salt1);
  540. if (stream.loadFile(file))
  541. return 1;
  542. return stream_readuserfile(stream, ret);
  543. }
  544. int stream_readuserfile(bd::Stream& stream, struct userrec **ret)
  545. {
  546. char *p = NULL, buf[1024] = "", lasthand[512] = "", *attr = NULL, *pass = NULL;
  547. char *code = NULL, s1[1024] = "", *s = buf, ignored[512] = "";
  548. struct userrec *bu = NULL, *u = NULL;
  549. struct chanset_t *cst = NULL;
  550. struct flag_record fr;
  551. struct chanuserrec *cr = NULL;
  552. int i, line = 0;
  553. bu = (*ret);
  554. if (bu == userlist) {
  555. clear_chanlist();
  556. lastuser = NULL;
  557. global_bans = NULL;
  558. global_ign = NULL;
  559. global_exempts = NULL;
  560. global_invites = NULL;
  561. }
  562. noshare = 1;
  563. /* read opening comment */
  564. bd::String str(stream.getline(180));
  565. if (unlikely(str[1] < '4')) {
  566. putlog(LOG_MISC, "*", "!*! Empty or malformed userfile.");
  567. return 0;
  568. }
  569. if (unlikely(str[1] > '4')) {
  570. putlog(LOG_MISC, "*", "Invalid userfile format.");
  571. return 0;
  572. }
  573. while (stream.tell() < stream.length()) {
  574. s = buf;
  575. str = stream.getline(sizeof(buf)).chomp();
  576. strlcpy(s, str.c_str(), std::min(str.length() + 1, sizeof(buf)));
  577. if (1) {
  578. line++;
  579. if (s[0] != '#' && s[0] != ';' && s[0]) {
  580. code = newsplit(&s);
  581. rmspace(s);
  582. if (!strcmp(code, "-")) { /* ignores/bans */
  583. if (!lasthand[0])
  584. continue; /* Skip this entry. */
  585. if (u) { /* only break it down if there a real users */
  586. p = strchr(s, ',');
  587. while (p != NULL) {
  588. splitc(s1, s, ',');
  589. rmspace(s1);
  590. if (s1[0])
  591. set_user(&USERENTRY_HOSTS, u, s1);
  592. p = strchr(s, ',');
  593. }
  594. }
  595. /* channel bans are never stacked with , */
  596. if (s[0]) {
  597. if (lasthand[0] && strchr(CHANMETA, lasthand[0]) != NULL)
  598. restore_chanmask('b', cst, s);
  599. else if (lasthand[0] == '*') {
  600. if (lasthand[1] == IGNORE_NAME[1])
  601. restore_ignore(s);
  602. else if (lasthand[1] == SET_NAME[1]) {
  603. set_cmd_pass(s, 0); /* no need to share here, if we have a new userfile
  604. * then leaf bots under us also get the new userfile */
  605. }
  606. else
  607. restore_chanmask('b', NULL, s);
  608. } else if (lasthand[0])
  609. set_user(&USERENTRY_HOSTS, u, s);
  610. }
  611. } else if (!strcmp(code, "%")) { /* exemptmasks */
  612. if (!lasthand[0])
  613. continue; /* Skip this entry. */
  614. if (s[0]) {
  615. if (lasthand[0] == '#' || lasthand[0] == '+')
  616. restore_chanmask('e', cst, s);
  617. else if (lasthand[0] == '*')
  618. if (lasthand[1] == EXEMPT_NAME[1])
  619. restore_chanmask('e', NULL, s);
  620. }
  621. } else if (!strcmp(code, "@")) { /* Invitemasks */
  622. if (!lasthand[0])
  623. continue; /* Skip this entry. */
  624. if (s[0]) {
  625. if (lasthand[0] == '#' || lasthand[0] == '+') {
  626. restore_chanmask('I', cst, s);
  627. } else if (lasthand[0] == '*') {
  628. if (lasthand[1] == INVITE_NAME[1]) {
  629. restore_chanmask('I', NULL, s);
  630. } else if (lasthand[1] == SET_NAME[1]) {
  631. var_userfile_share_line(s, -1, 0);
  632. }
  633. }
  634. }
  635. } else if (!strcmp(code, "!")) { /* user channel record */
  636. /* ! #chan laston flags [info] */
  637. char *chname = NULL, *st = NULL, *fl = NULL;
  638. if (u) {
  639. chname = newsplit(&s);
  640. st = newsplit(&s);
  641. fl = newsplit(&s);
  642. rmspace(s);
  643. fr.match = FR_CHAN;
  644. if (u->bot)
  645. fr.match |= FR_BOT;
  646. break_down_flags(fl, &fr, 0);
  647. if (findchan_by_dname(chname)) {
  648. for (cr = u->chanrec; cr; cr = cr->next)
  649. if (!rfc_casecmp(cr->channel, chname))
  650. break;
  651. if (!cr) {
  652. cr = (struct chanuserrec *) calloc(1, sizeof(struct chanuserrec));
  653. cr->next = u->chanrec;
  654. u->chanrec = cr;
  655. strlcpy(cr->channel, chname, 80);
  656. cr->laston = atoi(st);
  657. cr->flags = fr.chan;
  658. if (s[0]) {
  659. cr->info = strdup(s);
  660. } else
  661. cr->info = NULL;
  662. }
  663. }
  664. }
  665. } else if (!strcmp(code, "+")) { /* add channel record */
  666. if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
  667. char *options = NULL, *chan = NULL, *my_ptr = NULL;
  668. char resultbuf[RESULT_LEN] = "";
  669. options = my_ptr = strdup(s);
  670. newsplit(&options);
  671. newsplit(&options);
  672. chan = newsplit(&options);
  673. /* hack to remove { } */
  674. newsplit(&options);
  675. options[strlen(options) - 1] = 0;
  676. if (channel_add(resultbuf, chan, options) != OK) {
  677. putlog(LOG_MISC, "*", "Channel parsing error in userfile on line %d", line);
  678. free(my_ptr);
  679. noshare = 0;
  680. return 0;
  681. }
  682. free(my_ptr);
  683. }
  684. } else if (!strncmp(code, "::", 2)) { /* channel-specific bans */
  685. strlcpy(lasthand, &code[2], sizeof(lasthand));
  686. u = NULL;
  687. if (!findchan_by_dname(lasthand)) {
  688. strlcpy(s1, lasthand, sizeof(s1));
  689. strlcat(s1, " ", sizeof(s1));
  690. if (strstr(ignored, s1) == NULL) {
  691. strlcat(ignored, lasthand, sizeof(ignored));
  692. strlcat(ignored, " ", sizeof(ignored));
  693. }
  694. lasthand[0] = 0;
  695. } else {
  696. /* Remove all bans for this channel to avoid dupes */
  697. /* NOTE only remove bans for when getting a userfile
  698. * from another bot & that channel is shared */
  699. cst = findchan_by_dname(lasthand);
  700. clear_masks(cst->bans);
  701. cst->bans = NULL;
  702. }
  703. } else if (!strncmp(code, "&&", 2)) { /* channel-specific exempts */
  704. strlcpy(lasthand, &code[2], sizeof(lasthand));
  705. u = NULL;
  706. if (!findchan_by_dname(lasthand)) {
  707. strlcpy(s1, lasthand, sizeof(s1));
  708. strlcat(s1, " ", sizeof(s1));
  709. if (strstr(ignored, s1) == NULL) {
  710. strlcat(ignored, lasthand, sizeof(ignored));
  711. strlcat(ignored, " ", sizeof(ignored));
  712. }
  713. lasthand[0] = 0;
  714. } else {
  715. /* Remove all exempts for this channel to avoid dupes */
  716. /* NOTE only remove exempts for when getting a userfile
  717. * from another bot & that channel is shared */
  718. cst = findchan_by_dname(lasthand);
  719. clear_masks(cst->exempts);
  720. cst->exempts = NULL;
  721. }
  722. } else if (!strncmp(code, "$$", 2)) { /* channel-specific invites */
  723. strlcpy(lasthand, &code[2], sizeof(lasthand));
  724. u = NULL;
  725. if (!findchan_by_dname(lasthand)) {
  726. strlcpy(s1, lasthand, sizeof(s1));
  727. strlcat(s1, " ", sizeof(s1));
  728. if (strstr(ignored, s1) == NULL) {
  729. strlcat(ignored, lasthand, sizeof(ignored));
  730. strlcat(ignored, " ", sizeof(ignored));
  731. }
  732. lasthand[0] = 0;
  733. } else {
  734. /* Remove all invites for this channel to avoid dupes */
  735. /* NOTE only remove invites for when getting a userfile
  736. * from another bot & that channel is shared */
  737. cst = findchan_by_dname(lasthand);
  738. clear_masks(cst->invites);
  739. cst->invites = NULL;
  740. }
  741. } else if (!strncmp(code, "--", 2)) { /* user USERENTRY */
  742. if (u) {
  743. /* new format storage */
  744. struct user_entry *ue = NULL;
  745. int ok = 0;
  746. for (ue = u->entries; ue && !ok; ue = ue->next)
  747. if (ue->name && !strcasecmp(code + 2, ue->name)) {
  748. struct list_type *list = NULL;
  749. list = (struct list_type *) calloc(1, sizeof(struct list_type));
  750. list->next = NULL;
  751. list->extra = strdup(s);
  752. list_append((&ue->u.list), list);
  753. ok = 1;
  754. }
  755. /* if we don't have the entry, make it */
  756. if (!ok) {
  757. ue = (struct user_entry *) calloc(1, sizeof(struct user_entry));
  758. // ue->name = (char *) calloc(1, strlen(code + 1));
  759. ue->name = strdup(code + 2);
  760. ue->type = NULL;
  761. // strcpy(ue->name, code + 2);
  762. ue->u.list = (struct list_type *) calloc(1, sizeof(struct list_type));
  763. ue->u.list->next = NULL;
  764. ue->u.list->extra = strdup(s);
  765. list_insert((&u->entries), ue);
  766. }
  767. }
  768. } else if (!rfc_casecmp(code, BAN_NAME)) {
  769. strlcpy(lasthand, code, sizeof(lasthand));
  770. u = NULL;
  771. } else if (!rfc_casecmp(code, IGNORE_NAME)) {
  772. strlcpy(lasthand, code, sizeof(lasthand));
  773. u = NULL;
  774. } else if (!rfc_casecmp(code, EXEMPT_NAME)) {
  775. strlcpy(lasthand, code, sizeof(lasthand));
  776. u = NULL;
  777. } else if (!rfc_casecmp(code, INVITE_NAME)) {
  778. strlcpy(lasthand, code, sizeof(lasthand));
  779. u = NULL;
  780. } else if (!rfc_casecmp(code, CHANS_NAME)) {
  781. strlcpy(lasthand, code, sizeof(lasthand));
  782. u = NULL;
  783. } else if (!rfc_casecmp(code, SET_NAME)) {
  784. strlcpy(lasthand, code, sizeof(lasthand));
  785. u = NULL;
  786. } else if (code[0] == '*') {
  787. lasthand[0] = 0;
  788. u = NULL;
  789. } else { /* its a user ! */
  790. pass = newsplit(&s); /* old style passwords */
  791. attr = newsplit(&s);
  792. rmspace(s);
  793. if (unlikely(!attr[0] || !pass[0])) {
  794. putlog(LOG_MISC, "*", "* Corrupt user record line: %d!", line);
  795. lasthand[0] = 0;
  796. noshare = 0;
  797. return 0;
  798. } else {
  799. int isbot = 0;
  800. if (code[0] == '-') {
  801. code++;
  802. isbot++;
  803. }
  804. u = get_user_by_handle(bu, code);
  805. if (unlikely(u)) {
  806. putlog(LOG_ERROR, "@", "* Duplicate user record '%s'!", code);
  807. lasthand[0] = 0;
  808. u = NULL;
  809. } else {
  810. fr.match = FR_GLOBAL;
  811. if (isbot)
  812. fr.match |= FR_BOT;
  813. break_down_flags(attr, &fr, 0);
  814. strlcpy(lasthand, code, sizeof(lasthand));
  815. cst = NULL;
  816. if (strlen(code) > HANDLEN)
  817. code[HANDLEN] = 0;
  818. if (unlikely(strlen(pass) > 20)) { /* old style passwords */
  819. putlog(LOG_MISC, "*", "* Corrupted password reset for '%s'", code);
  820. pass[0] = '-';
  821. pass[1] = 0;
  822. }
  823. bu = adduser(bu, code, 0, pass, sanity_check(fr.global, isbot), isbot);
  824. u = get_user_by_handle(bu, code);
  825. for (i = 0; i < dcc_total; i++)
  826. if (dcc[i].type && !strcasecmp(code, dcc[i].nick))
  827. dcc[i].user = u;
  828. if (!strcasecmp(code, conf.bot->nick))
  829. conf.bot->u = u;
  830. /* if s starts with '/' it's got file info */
  831. }
  832. }
  833. }
  834. }
  835. }
  836. }
  837. (*ret) = bu;
  838. if (ignored[0]) {
  839. putlog(LOG_MISC, "*", "Ignored masks for channel(s): %s", ignored);
  840. }
  841. putlog(LOG_MISC, "*", "Userfile loaded, unpacking...");
  842. for (u = bu; u; u = u->next) {
  843. struct user_entry *e = NULL;
  844. if (unlikely(!u->bot && !strcasecmp (u->handle, conf.bot->nick))) {
  845. putlog(LOG_MISC, "*", "(!) I have a user record, but am not classified as a BOT!");
  846. u->bot = 1;
  847. }
  848. for (e = u->entries; e; e = e->next)
  849. if (likely(e->name)) {
  850. struct user_entry_type *uet = find_entry_type(e->name);
  851. if (uet) {
  852. e->type = uet;
  853. uet->unpack(u, e);
  854. free(e->name);
  855. e->name = NULL;
  856. } else
  857. sdprintf("FAILED TO UNPACK '%s'", e->name);
  858. }
  859. }
  860. /* process the user data *now* */
  861. if (!conf.bot->hub)
  862. unlink(userfile);
  863. noshare = 0;
  864. return 1;
  865. }
  866. void link_pref_val(struct userrec *u, char *val)
  867. {
  868. /* val must be HANDLEN + 4 chars minimum */
  869. val[0] = 'Z';
  870. val[1] = 0;
  871. if (!u)
  872. return;
  873. if (!u->bot)
  874. return;
  875. struct bot_addr *ba = NULL;
  876. if (!(ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u))) {
  877. return;
  878. }
  879. if (!ba->hublevel || ba->hublevel == 999) {
  880. return;
  881. }
  882. simple_snprintf(val, HANDLEN + 4, "%02d%s", ba->hublevel, u->handle);
  883. }
  884. /*
  885. starting at "current" or "userlist" if NULL, find next bot with a
  886. link_pref_val higher than "lowval" and lower than "highval"
  887. If none found return bot with best overall link_pref_val
  888. If still not found return NULL
  889. */
  890. struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
  891. {
  892. char thisval[HANDLEN + 4] = "", bestmatchval[HANDLEN + 4] = "z", bestallval[HANDLEN + 4] = "z";
  893. struct userrec *cur = NULL, *bestmatch = NULL, *bestall = NULL;
  894. if (current)
  895. cur = current->next;
  896. else
  897. cur = userlist;
  898. while (cur != current) {
  899. if (!cur)
  900. cur = userlist;
  901. if (cur == current)
  902. break;
  903. if (cur->bot && (strcasecmp(cur->handle, conf.bot->nick))) {
  904. link_pref_val(cur, thisval);
  905. if ((strcmp(thisval, lowval) < 0) && (strcmp(thisval, highval) > 0) &&(strcmp(thisval, bestmatchval) < 0)) {
  906. strlcpy(bestmatchval, thisval, sizeof(bestmatchval));
  907. bestmatch = cur;
  908. }
  909. if ((strcmp(thisval, lowval) < 0) && (strcmp(thisval, bestallval) < 0)) {
  910. strlcpy(bestallval, thisval, sizeof(bestallval));
  911. bestall = cur;
  912. }
  913. }
  914. cur = cur->next;
  915. }
  916. if (bestmatch)
  917. return bestmatch;
  918. if (bestall)
  919. return bestall;
  920. return NULL;
  921. }
  922. static void autolink_cycle_hub(char *start)
  923. {
  924. char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
  925. tand_t *bot = NULL;
  926. link_pref_val(conf.bot->u, myval);
  927. strlcpy(bestval, myval, sizeof(bestval));
  928. for (int i = 0; i < dcc_total; i++) {
  929. if (dcc[i].type) {
  930. if (dcc[i].type == &DCC_BOT_NEW)
  931. return;
  932. if (dcc[i].type == &DCC_FORK_BOT)
  933. return;
  934. if (dcc[i].type == &DCC_BOT) {
  935. if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
  936. continue; /* lets let the binary update have its peace. */
  937. if ((bot = findbot(dcc[i].nick)) && bot->buildts != buildts)
  938. continue; /* same thing. */
  939. if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {
  940. link_pref_val(dcc[i].user, curval);
  941. if (strcmp(myval, curval) < 0) {
  942. /* I should be aggressive to this one */
  943. if (dcc[i].status & STAT_AGGRESSIVE) {
  944. putlog(LOG_MISC, "*", "Passively sharing with %s but should be aggressive", dcc[i].user->handle);
  945. putlog(LOG_DEBUG, "*", "My linkval: %s - %s linkval: %s", myval, dcc[i].nick, curval);
  946. botunlink(-2, dcc[i].nick, "Marked passive, should be aggressive");
  947. return;
  948. }
  949. } else {
  950. /* I should be passive to this one */
  951. if (!(dcc[i].status & STAT_AGGRESSIVE)) {
  952. putlog(LOG_MISC, "*", "Aggressively sharing with %s but should be passive", dcc[i].user->handle);
  953. putlog(LOG_DEBUG, "*", "My linkval: %s - %s linkval: %s", myval, dcc[i].nick, curval);
  954. botunlink(-2, dcc[i].nick, "Marked aggressive, should be passive");
  955. return;
  956. }
  957. if (strcmp(curval, bestval) < 0)
  958. strlcpy(bestval, curval, sizeof(bestval));
  959. }
  960. }
  961. }
  962. }
  963. }
  964. struct userrec *u = NULL;
  965. if (start)
  966. u = get_user_by_handle(userlist, start);
  967. if (u) {
  968. link_pref_val(u, curval);
  969. if (strcmp(bestval, curval) < 0) {
  970. /* This happens if we're already connected to a good hub but we failed to link to another hub as well
  971. can happen if you .link.... but it's nothing FATAL :) */
  972. /* This shouldn't happen. Getting a failed link attempt (start!=NULL)
  973. while a dcc scan indicates we *are* connected to a better bot than
  974. the one we failed a link to.
  975. */
  976. // putlog(LOG_BOTS, "*", "Failed link attempt to %s but connected to %s already???", u->handle, (char *) &bestval[2]);
  977. return;
  978. }
  979. } else
  980. strlcpy(curval, "0", sizeof(curval));
  981. /* link to the (highlest level)/best hub */
  982. u = next_hub(u, bestval, curval);
  983. if (u && !in_chain(u->handle))
  984. botlink("", -3, u->handle);
  985. }
  986. typedef struct hublist_entry {
  987. struct hublist_entry *next;
  988. struct userrec *u;
  989. } tag_hublist_entry;
  990. int botlinkcount = 0;
  991. static void autolink_random_hub(char *avoidbot) {
  992. /* Pick a random hub, but avoid 'avoidbot' */
  993. int hlc = 0;
  994. struct hublist_entry *hl = NULL, *hl2 = NULL;
  995. struct userrec *tmpu = NULL;
  996. struct flag_record fr = { FR_GLOBAL|FR_BOT, 0, 0, 0 };
  997. for (struct userrec *u = userlist; u; u = u->next) {
  998. get_user_flagrec(u, &fr, NULL);
  999. if (glob_bot(fr) && strcasecmp(u->handle, conf.bot->nick) && (bot_hublevel(u) < 999)) {
  1000. if (strcmp(u->handle, avoidbot)) {
  1001. hl2 = hl;
  1002. hl = (struct hublist_entry *) calloc(1, sizeof(struct hublist_entry));
  1003. hl->next = hl2;
  1004. hlc++;
  1005. hl->u = u;
  1006. } else
  1007. tmpu = u;
  1008. }
  1009. }
  1010. /* We probably have 1 hub and avoided it :/ */
  1011. if (!hlc && tmpu) {
  1012. hl2 = hl;
  1013. hl = (struct hublist_entry *) calloc(1, sizeof(struct hublist_entry));
  1014. hl->next = hl2;
  1015. hlc++;
  1016. hl->u = tmpu;
  1017. }
  1018. hlc = randint(hlc);
  1019. while (hl) {
  1020. if (!hlc) {
  1021. botlink("", -3, hl->u->handle);
  1022. }
  1023. hlc--;
  1024. hl2 = hl->next;
  1025. free(hl);
  1026. hl = hl2;
  1027. }
  1028. }
  1029. static void autolink_cycle_leaf(char *start)
  1030. {
  1031. struct bot_addr *my_ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
  1032. char uplink[HANDLEN + 1] = "", avoidbot[HANDLEN + 1] = "", curhub[HANDLEN + 1] = "";
  1033. /* Reset connection attempts if we ain't called due to a failed link */
  1034. if (!start)
  1035. botlinkcount = 0;
  1036. if (my_ba && (my_ba->uplink[0])) {
  1037. strlcpy(uplink, my_ba->uplink, sizeof(uplink));
  1038. }
  1039. for (int i = 0; i < dcc_total; i++) {
  1040. if (dcc[i].type) {
  1041. if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
  1042. return;
  1043. if (dcc[i].hub && dcc[i].type == &DCC_BOT) {
  1044. strlcpy(curhub, dcc[i].nick, sizeof(curhub));
  1045. break;
  1046. }
  1047. }
  1048. }
  1049. if (curhub[0]) {
  1050. /* we are linked to a bot (hub) */
  1051. if (uplink[0] && !strcmp(curhub, uplink))
  1052. /* Connected to uplink, nothing more to do */
  1053. return;
  1054. if (start)
  1055. /* Failed a link... let's just wait for next regular call */
  1056. return;
  1057. if (dont_restructure)
  1058. return;
  1059. if (uplink[0]) {
  1060. /* Trying the uplink */
  1061. botlink("", -3, uplink);
  1062. return;
  1063. }
  1064. /* we got a hub currently, and no set uplink. Stay here */
  1065. return;
  1066. } else {
  1067. /* no hubs connected... pick one */
  1068. if (!start) {
  1069. /* Regular interval call, no previous failed link */
  1070. if (uplink[0]) {
  1071. /* We have a set uplink, try it */
  1072. botlink("", -3, uplink);
  1073. return;
  1074. }
  1075. /* No preferred uplink, we need a random bot */
  1076. avoidbot[0] = 0;
  1077. } else {
  1078. /* We got a failed link... */
  1079. botlinkcount++;
  1080. if (botlinkcount >= 3)
  1081. /* tried 3+ random hubs without success, wait for next regular interval call */
  1082. return;
  1083. /* We need a random bot but *not* the last we tried */
  1084. strlcpy(avoidbot, start, sizeof(avoidbot));
  1085. }
  1086. }
  1087. autolink_random_hub(avoidbot);
  1088. }
  1089. void autolink_cycle()
  1090. {
  1091. char start[HANDLEN + 1] = "";
  1092. if (autolink_failed[0]) {
  1093. strlcpy(start, autolink_failed, HANDLEN + 1);
  1094. autolink_failed[0] = 0;
  1095. }
  1096. if (conf.bot->hub)
  1097. autolink_cycle_hub(start[0] ? start : NULL);
  1098. else if (conf.bot->localhub)
  1099. autolink_cycle_leaf(start[0] ? start : NULL);
  1100. else { //Connect to the localhub
  1101. if (tands == 0) {
  1102. // Make sure not already trying for the localhub
  1103. for (int i = 0; i < dcc_total; i++) {
  1104. if (dcc[i].type) {
  1105. if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
  1106. return;
  1107. }
  1108. }
  1109. sdprintf("need to link to my localhub: %s\n", conf.localhub);
  1110. botlink("", -3, conf.localhub);
  1111. }
  1112. }
  1113. }
  1114. void check_stale_dcc_users()
  1115. {
  1116. for (int i = 0; i < dcc_total; ++i) {
  1117. if (!dcc[i].type || !dcc[i].nick[0]) continue;
  1118. if (dcc[i].user == NULL && !(dcc[i].user = get_user_by_handle(userlist, dcc[i].nick))) { /* Removed user */
  1119. if (dcc[i].type == &DCC_BOT || dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_NEW)
  1120. botunlink(i, dcc[i].nick, "No longer a valid bot.");
  1121. else if (dcc[i].type == &DCC_CHAT) {
  1122. if (!backgrd && term_z && !strcmp(dcc[i].nick, "HQ"))
  1123. setup_HQ(i);
  1124. else
  1125. do_boot(i, "internal", "No longer a valid user.");
  1126. }
  1127. }
  1128. }
  1129. }
  1130. /* vim: set sts=2 sw=2 ts=8 et: */