users.c 34 KB

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