users.c 33 KB

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