/[cvs]/eggdrop1.9/src/userrec.c
ViewVC logotype

Contents of /eggdrop1.9/src/userrec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.19 - (show annotations) (download) (as text)
Wed Apr 5 19:55:13 2000 UTC (19 years, 9 months ago) by fabian
Branch: MAIN
CVS Tags: eggdrop10503, eggdrop10403
Changes since 1.18: +7 -5 lines
File MIME type: text/x-chdr
mem_debug_fix patch

1 /*
2 * userrec.c -- handles:
3 * add_q() del_q() str2flags() flags2str() str2chflags() chflags2str()
4 * a bunch of functions to find and change user records
5 * change and check user (and channel-specific) flags
6 *
7 * $Id: userrec.c,v 1.18 2000/03/23 23:17:56 fabian Exp $
8 */
9 /*
10 * Copyright (C) 1997 Robey Pointer
11 * Copyright (C) 1999, 2000 Eggheads
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
28 #include <sys/stat.h>
29 #include "main.h"
30 #include "users.h"
31 #include "chan.h"
32 #include "modules.h"
33 #include "tandem.h"
34
35 extern struct dcc_t *dcc;
36 extern struct chanset_t *chanset;
37 extern int default_flags, default_uflags, quiet_save,
38 dcc_total, share_greet;
39 extern char userfile[], ver[], botnetnick[];
40 extern time_t now;
41
42 int noshare = 1; /* don't send out to sharebots */
43 int sort_users = 0; /* sort the userlist when saving */
44 struct userrec *userlist = NULL; /* user records are stored here */
45 struct userrec *lastuser = NULL; /* last accessed user record */
46 maskrec *global_bans = NULL,
47 *global_exempts = NULL,
48 *global_invites = NULL;
49 struct igrec *global_ign = NULL;
50 int cache_hit = 0,
51 cache_miss = 0; /* temporary cache accounting */
52 int strict_host = 1;
53 int userfile_perm = 0600; /* Userfile permissions,
54 default rw------- */
55
56
57 #ifdef DEBUG_MEM
58 void *_user_malloc(int size, char *file, int line)
59 {
60 char x[1024], *p;
61
62 p = strrchr(file, '/');
63 simple_sprintf(x, "userrec.c:%s", p ? p + 1 : file);
64 return n_malloc(size, x, line);
65 }
66
67 void *_user_realloc(void *ptr, int size, char *file, int line)
68 {
69 char x[1024], *p;
70
71 p = strrchr(file, '/');
72 simple_sprintf(x, "userrec.c:%s", p ? p + 1 : file);
73 return n_realloc(ptr, size, x, line);
74 }
75 #else
76 void *_user_malloc(int size, char *file, int line)
77 {
78 return nmalloc(size);
79 }
80
81 void *_user_realloc(void *ptr, int size, char *file, int line)
82 {
83 return nrealloc(ptr, size);
84 }
85 #endif
86
87 inline int expmem_mask(struct maskrec *m)
88 {
89 int result = 0;
90
91 while (m) {
92 result += sizeof(struct maskrec);
93 result += strlen(m->mask) + 1;
94 if (m->user)
95 result += strlen(m->user) + 1;
96 if (m->desc)
97 result += strlen(m->desc) + 1;
98
99 m = m->next;
100 }
101
102 return result;
103 }
104
105 /* Memory we should be using
106 */
107 int expmem_users()
108 {
109 int tot;
110 struct userrec *u;
111 struct chanuserrec *ch;
112 struct chanset_t *chan;
113 struct user_entry *ue;
114 struct igrec *i;
115
116 Context;
117 tot = 0;
118 u = userlist;
119 while (u != NULL) {
120 ch = u->chanrec;
121 while (ch) {
122 tot += sizeof(struct chanuserrec);
123
124 if (ch->info != NULL)
125 tot += strlen(ch->info) + 1;
126 ch = ch->next;
127 }
128 tot += sizeof(struct userrec);
129
130 for (ue = u->entries; ue; ue = ue->next) {
131 tot += sizeof(struct user_entry);
132
133 if (ue->name) {
134 tot += strlen(ue->name) + 1;
135 tot += list_type_expmem(ue->u.list);
136 } else {
137 tot += ue->type->expmem(ue);
138 }
139 }
140 u = u->next;
141 }
142 /* Account for each channel's masks */
143 for (chan = chanset; chan; chan = chan->next) {
144
145 /* Account for each channel's ban-list user */
146 tot += expmem_mask(chan->bans);
147
148 /* Account for each channel's exempt-list user */
149 tot += expmem_mask(chan->exempts);
150
151 /* Account for each channel's invite-list user */
152 tot += expmem_mask(chan->invites);
153 }
154
155 tot += expmem_mask(global_bans);
156 tot += expmem_mask(global_exempts);
157 tot += expmem_mask(global_invites);
158
159 for (i = global_ign; i; i = i->next) {
160 tot += sizeof(struct igrec);
161
162 tot += strlen(i->igmask) + 1;
163 if (i->user)
164 tot += strlen(i->user) + 1;
165 if (i->msg)
166 tot += strlen(i->msg) + 1;
167 }
168 return tot;
169 }
170
171 int count_users(struct userrec *bu)
172 {
173 int tot = 0;
174 struct userrec *u = bu;
175
176 while (u != NULL) {
177 tot++;
178 u = u->next;
179 }
180 return tot;
181 }
182
183 /* Convert "nick!~user@host", "nick!+user@host" and "nick!-user@host"
184 * to "nick!user@host" if necessary. (drummer)
185 */
186 static char *fixfrom(char *s)
187 {
188 char *p;
189 static char buf[512];
190
191 if (s == NULL)
192 return NULL;
193 strncpy(buf, s, 511);
194 buf[511] = 0;
195 if (strict_host)
196 return buf;
197 if ((p = strchr(buf, '!')))
198 p++;
199 else
200 p = s; /* Sometimes we get passed just a
201 * user@host here... */
202 /* These are ludicrous. */
203 if (strchr("~+-^=", *p) && (p[1] != '@')) /* added check for @ - drummer */
204 strcpy(p, p + 1);
205 /* Bug was: n!~@host -> n!@host now: n!~@host */
206 return buf;
207 }
208
209 struct userrec *check_dcclist_hand(char *handle)
210 {
211 int i;
212
213 for (i = 0; i < dcc_total; i++)
214 if (!egg_strcasecmp(dcc[i].nick, handle))
215 return dcc[i].user;
216 return NULL;
217 }
218
219 struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
220 {
221 struct userrec *u = bu, *ret;
222
223 if (!handle)
224 return NULL;
225 rmspace(handle);
226 if (!handle[0] || (handle[0] == '*'))
227 return NULL;
228 if (bu == userlist) {
229 if (lastuser && !egg_strcasecmp(lastuser->handle, handle)) {
230 cache_hit++;
231 return lastuser;
232 }
233 ret = check_dcclist_hand(handle);
234 if (ret) {
235 cache_hit++;
236 return ret;
237 }
238 ret = check_chanlist_hand(handle);
239 if (ret) {
240 cache_hit++;
241 return ret;
242 }
243 cache_miss++;
244 }
245 while (u) {
246 if (!egg_strcasecmp(u->handle, handle)) {
247 if (bu == userlist)
248 lastuser = u;
249 return u;
250 }
251 u = u->next;
252 }
253 return NULL;
254 }
255
256 /* Fix capitalization, etc
257 */
258 void correct_handle(char *handle)
259 {
260 struct userrec *u;
261
262 u = get_user_by_handle(userlist, handle);
263 if (u == NULL)
264 return;
265 strcpy(handle, u->handle);
266 }
267
268 /* This will be usefull in a lot of places, much more code re-use so we
269 * endup with a smaller executable bot. <cybah>
270 */
271 void clear_masks(maskrec *m)
272 {
273 maskrec *temp = NULL;
274
275 while (m) {
276 temp = m->next;
277
278 if (m->mask)
279 nfree(m->mask);
280 if (m->user)
281 nfree(m->user);
282 if (m->desc)
283 nfree(m->desc);
284
285 nfree(m);
286 m = temp;
287 }
288 }
289
290 void clear_userlist(struct userrec *bu)
291 {
292 struct userrec *u = bu, *v;
293 int i;
294
295 Context;
296 while (u != NULL) {
297 v = u->next;
298 freeuser(u);
299 u = v;
300 }
301 if (userlist == bu) {
302 struct chanset_t *cst;
303
304 for (i = 0; i < dcc_total; i++)
305 dcc[i].user = NULL;
306 clear_chanlist();
307 lastuser = NULL;
308
309 while (global_ign)
310 delignore(global_ign->igmask);
311
312 clear_masks(global_bans);
313 clear_masks(global_exempts);
314 clear_masks(global_invites);
315 global_exempts = global_invites = global_bans = NULL;
316
317 for (cst = chanset; cst; cst = cst->next) {
318 clear_masks(cst->bans);
319 clear_masks(cst->exempts);
320 clear_masks(cst->invites);
321
322 cst->bans = cst->exempts = cst->invites = NULL;
323 }
324 }
325 /* Remember to set your userlist to NULL after calling this */
326 Context;
327 }
328
329 /* Find CLOSEST host match
330 * (if "*!*@*" and "*!*@*clemson.edu" both match, use the latter!)
331 *
332 * Checks the chanlist first, to possibly avoid needless search.
333 */
334 struct userrec *get_user_by_host(char *host)
335 {
336 struct userrec *u = userlist, *ret;
337 struct list_type *q;
338 int cnt, i;
339
340 if (host == NULL)
341 return NULL;
342 rmspace(host);
343 if (!host[0])
344 return NULL;
345 ret = check_chanlist(host);
346 cnt = 0;
347 if (ret != NULL) {
348 cache_hit++;
349 return ret;
350 }
351 cache_miss++;
352 host = fixfrom(host);
353 while (u != NULL) {
354 q = get_user(&USERENTRY_HOSTS, u);
355 while (q != NULL) {
356 i = wild_match(q->extra, host);
357 if (i > cnt) {
358 ret = u;
359 cnt = i;
360 }
361 q = q->next;
362 }
363 u = u->next;
364 }
365 if (ret != NULL) {
366 lastuser = ret;
367 set_chanlist(host, ret);
368 }
369 return ret;
370 }
371
372 /* use fixfrom() or dont? (drummer)
373 */
374 struct userrec *get_user_by_equal_host(char *host)
375 {
376 struct userrec *u = userlist;
377 struct list_type *q;
378
379 while (u != NULL) {
380 q = get_user(&USERENTRY_HOSTS, u);
381 while (q != NULL) {
382 if (!rfc_casecmp(q->extra, host))
383 return u;
384 q = q->next;
385 }
386 u = u->next;
387 }
388 return NULL;
389 }
390
391 /* Try: pass_match_by_host("-",host)
392 * will return 1 if no password is set for that host
393 */
394 int u_pass_match(struct userrec *u, char *pass)
395 {
396 char *cmp, new[32];
397
398 if (!u)
399 return 0;
400 cmp = get_user(&USERENTRY_PASS, u);
401 if (!cmp && (!pass[0] || (pass[0] == '-')))
402 return 1;
403 if (!cmp || !pass || !pass[0] || (pass[0] == '-'))
404 return 0;
405 if (u->flags & USER_BOT) {
406 if (!strcmp(cmp, pass))
407 return 1;
408 } else {
409 if (strlen(pass) > 15)
410 pass[15] = 0;
411 encrypt_pass(pass, new);
412 if (!strcmp(cmp, new))
413 return 1;
414 }
415 return 0;
416 }
417
418 int write_user(struct userrec *u, FILE * f, int idx)
419 {
420 char s[181];
421 struct chanuserrec *ch;
422 struct chanset_t *cst;
423 struct user_entry *ue;
424 struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
425
426 fr.global = u->flags;
427 fr.udef_global = u->flags_udef;
428 build_flags(s, &fr, NULL);
429 if (fprintf(f, "%-10s - %-24s\n", u->handle, s) == EOF)
430 return 0;
431 for (ch = u->chanrec; ch; ch = ch->next) {
432 cst = findchan_by_dname(ch->channel);
433 if (cst && ((idx < 0) || channel_shared(cst))) {
434 if (idx >= 0) {
435 fr.match = (FR_CHAN | FR_BOT);
436 get_user_flagrec(dcc[idx].user, &fr, ch->channel);
437 } else
438 fr.chan = BOT_SHARE;
439 if ((fr.chan & BOT_SHARE) || (fr.bot & BOT_GLOBAL)) {
440 fr.match = FR_CHAN;
441 fr.chan = ch->flags;
442 fr.udef_chan = ch->flags_udef;
443 build_flags(s, &fr, NULL);
444 if (fprintf(f, "! %-20s %lu %-10s %s\n", ch->channel, ch->laston, s,
445 (((idx < 0) || share_greet) && ch->info) ? ch->info
446 : "") == EOF)
447 return 0;
448 }
449 }
450 }
451 for (ue = u->entries; ue; ue = ue->next) {
452 if (ue->name) {
453 struct list_type *lt;
454
455 for (lt = ue->u.list; lt; lt = lt->next)
456 if (fprintf(f, "--%s %s\n", ue->name, lt->extra) == EOF)
457 return 0;
458 } else {
459 if (!ue->type->write_userfile(f, u, ue))
460 return 0;
461 }
462 }
463 return 1;
464 }
465
466 int sort_compare(struct userrec *a, struct userrec *b)
467 {
468 /* Order by flags, then alphabetically
469 * first bots: +h / +a / +l / other bots
470 * then users: +n / +m / +o / other users
471 * return true if (a > b)
472 */
473 if (a->flags & b->flags & USER_BOT) {
474 if (~bot_flags(a) & bot_flags(b) & BOT_HUB)
475 return 1;
476 if (bot_flags(a) & ~bot_flags(b) & BOT_HUB)
477 return 0;
478 if (~bot_flags(a) & bot_flags(b) & BOT_ALT)
479 return 1;
480 if (bot_flags(a) & ~bot_flags(b) & BOT_ALT)
481 return 0;
482 if (~bot_flags(a) & bot_flags(b) & BOT_LEAF)
483 return 1;
484 if (bot_flags(a) & ~bot_flags(b) & BOT_LEAF)
485 return 0;
486 } else {
487 if (~a->flags & b->flags & USER_BOT)
488 return 1;
489 if (a->flags & ~b->flags & USER_BOT)
490 return 0;
491 if (~a->flags & b->flags & USER_OWNER)
492 return 1;
493 if (a->flags & ~b->flags & USER_OWNER)
494 return 0;
495 if (~a->flags & b->flags & USER_MASTER)
496 return 1;
497 if (a->flags & ~b->flags & USER_MASTER)
498 return 0;
499 if (~a->flags & b->flags & USER_OP)
500 return 1;
501 if (a->flags & ~b->flags & USER_OP)
502 return 0;
503 }
504 return (egg_strcasecmp(a->handle, b->handle) > 0);
505 }
506
507 void sort_userlist()
508 {
509 int again;
510 struct userrec *last, *p, *c, *n;
511
512 again = 1;
513 last = NULL;
514 while ((userlist != last) && (again)) {
515 p = NULL;
516 c = userlist;
517 n = c->next;
518 again = 0;
519 while (n != last) {
520 if (sort_compare(c, n)) {
521 again = 1;
522 c->next = n->next;
523 n->next = c;
524 if (p == NULL)
525 userlist = n;
526 else
527 p->next = n;
528 }
529 p = c;
530 c = n;
531 n = n->next;
532 }
533 last = c;
534 }
535 }
536
537 /* Rewrite the entire user file. Also write the channel file at the same time
538 */
539 void write_userfile(int idx)
540 {
541 FILE *f;
542 char s[121], s1[81];
543 time_t tt;
544 struct userrec *u;
545 int ok;
546
547 Context;
548 if (userlist == NULL)
549 return; /* No point in saving userfile */
550 sprintf(s, "%s~new", userfile);
551 f = fopen(s, "w");
552 chmod(s, userfile_perm);
553 if (f == NULL) {
554 putlog(LOG_MISC, "*", USERF_ERRWRITE);
555 return;
556 }
557 if (!quiet_save)
558 putlog(LOG_MISC, "*", USERF_WRITING);
559 if (sort_users)
560 sort_userlist();
561 tt = now;
562 strcpy(s1, ctime(&tt));
563 fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s1);
564 Context;
565 ok = 1;
566 u = userlist;
567 while ((u != NULL) && (ok)) {
568 ok = write_user(u, f, idx);
569 u = u->next;
570 }
571 Context;
572 if (!ok || fflush(f)) {
573 putlog(LOG_MISC, "*", "%s (%s)", USERF_ERRWRITE, strerror(ferror(f)));
574 fclose(f);
575 return;
576 }
577 fclose(f);
578 Context;
579 call_hook(HOOK_USERFILE);
580 Context;
581 unlink(userfile);
582 sprintf(s, "%s~new", userfile);
583 movefile(s, userfile);
584 }
585
586 int change_handle(struct userrec *u, char *newh)
587 {
588 int i;
589 char s[16];
590
591 if (!u)
592 return 0;
593 /* Nothing that will confuse the userfile */
594 if ((newh[1] == 0) && strchr(BADHANDCHARS, newh[0]))
595 return 0;
596 check_tcl_nkch(u->handle, newh);
597 /* Yes, even send bot nick changes now: */
598 if ((!noshare) && !(u->flags & USER_UNSHARED))
599 shareout(NULL, "h %s %s\n", u->handle, newh);
600 strcpy(s, u->handle);
601 strcpy(u->handle, newh);
602 for (i = 0; i < dcc_total; i++) {
603 if (!egg_strcasecmp(dcc[i].nick, s) &&
604 (dcc[i].type != &DCC_BOT)) {
605 strcpy(dcc[i].nick, newh);
606 if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel >= 0)) {
607 chanout_but(-1, dcc[i].u.chat->channel,
608 "*** Nick change: %s -> %s\n", s, newh);
609 if (dcc[i].u.chat->channel < 100000)
610 botnet_send_nkch(i, s);
611 }
612 }
613 }
614 return 1;
615 }
616
617 extern int noxtra;
618
619 struct userrec *adduser(struct userrec *bu, char *handle, char *host,
620 char *pass, int flags)
621 {
622 struct userrec *u, *x;
623 struct xtra_key *xk;
624 int oldshare = noshare;
625
626 noshare = 1;
627 u = (struct userrec *) nmalloc(sizeof(struct userrec));
628
629 /* u->next=bu; bu=u; */
630 strncpy(u->handle, handle, HANDLEN);
631 u->handle[HANDLEN] = 0;
632 u->next = NULL;
633 u->chanrec = NULL;
634 u->entries = NULL;
635 if (flags != USER_DEFAULT) { /* drummer */
636 u->flags = flags;
637 u->flags_udef = 0;
638 } else {
639 u->flags = default_flags;
640 u->flags_udef = default_uflags;
641 }
642 set_user(&USERENTRY_PASS, u, pass);
643 if (!noxtra) {
644 xk = nmalloc(sizeof(struct xtra_key));
645
646 xk->key = nmalloc(8);
647 strcpy(xk->key, "created");
648 xk->data = nmalloc(10);
649 sprintf(xk->data, "%09lu", now);
650 set_user(&USERENTRY_XTRA, u, xk);
651 }
652 /* Strip out commas -- they're illegal */
653 if (host && host[0]) {
654 char *p;
655
656 /* About this fixfrom():
657 * We should use this fixfrom before every call of adduser()
658 * but its much easier to use here... (drummer)
659 * Only use it if we have a host :) (dw)
660 */
661 host = fixfrom(host);
662 p = strchr(host, ',');
663
664 while (p != NULL) {
665 *p = '?';
666 p = strchr(host, ',');
667 }
668 set_user(&USERENTRY_HOSTS, u, host);
669 } else
670 set_user(&USERENTRY_HOSTS, u, "none");
671 if (bu == userlist)
672 clear_chanlist();
673 noshare = oldshare;
674 if ((!noshare) && (handle[0] != '*') && (!(flags & USER_UNSHARED)) &&
675 (bu == userlist)) {
676 struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
677 char x[100];
678
679 fr.global = u->flags;
680 fr.udef_global = u->flags_udef;
681 build_flags(x, &fr, 0);
682 shareout(NULL, "n %s %s %s %s\n", handle, host, pass, x);
683 }
684 if (bu == NULL)
685 bu = u;
686 else {
687 if ((bu == userlist) && (lastuser != NULL))
688 x = lastuser;
689 else
690 x = bu;
691 while (x->next != NULL)
692 x = x->next;
693 x->next = u;
694 if (bu == userlist)
695 lastuser = u;
696 }
697 return bu;
698 }
699
700 void freeuser(struct userrec *u)
701 {
702 struct user_entry *ue, *ut;
703 struct chanuserrec *ch, *z;
704
705 if (u == NULL)
706 return;
707 ch = u->chanrec;
708 while (ch) {
709 z = ch;
710 ch = ch->next;
711 if (z->info != NULL)
712 nfree(z->info);
713 nfree(z);
714 }
715 u->chanrec = NULL;
716 for (ue = u->entries; ue; ue = ut) {
717 ut = ue->next;
718 if (ue->name) {
719 struct list_type *lt, *ltt;
720
721 for (lt = ue->u.list; lt; lt = ltt) {
722 ltt = lt->next;
723 nfree(lt->extra);
724 nfree(lt);
725 }
726 nfree(ue->name);
727 nfree(ue);
728 } else {
729 ue->type->kill(ue);
730 }
731 }
732 nfree(u);
733 }
734
735 int deluser(char *handle)
736 {
737 struct userrec *u = userlist, *prev = NULL;
738 int fnd = 0;
739
740 while ((u != NULL) && (!fnd)) {
741 if (!egg_strcasecmp(u->handle, handle))
742 fnd = 1;
743 else {
744 prev = u;
745 u = u->next;
746 }
747 }
748 if (!fnd)
749 return 0;
750 if (prev == NULL)
751 userlist = u->next;
752 else
753 prev->next = u->next;
754 if (!noshare && (handle[0] != '*') && !(u->flags & USER_UNSHARED))
755 shareout(NULL, "k %s\n", handle);
756 for (fnd = 0; fnd < dcc_total; fnd++)
757 if (dcc[fnd].user == u)
758 dcc[fnd].user = 0; /* Clear any dcc users for this entry,
759 * null is safe-ish */
760 clear_chanlist();
761 freeuser(u);
762 lastuser = NULL;
763 return 1;
764 }
765
766 int delhost_by_handle(char *handle, char *host)
767 {
768 struct userrec *u;
769 struct list_type *q, *qnext, *qprev;
770 struct user_entry *e = NULL;
771 int i = 0;
772
773 Context;
774 u = get_user_by_handle(userlist, handle);
775 if (!u)
776 return 0;
777 q = get_user(&USERENTRY_HOSTS, u);
778 qprev = q;
779 if (q) {
780 if (!rfc_casecmp(q->extra, host)) {
781 e = find_user_entry(&USERENTRY_HOSTS, u);
782 e->u.extra = q->next;
783 nfree(q->extra);
784 nfree(q);
785 i++;
786 qprev = NULL;
787 q = e->u.extra;
788 } else
789 q = q->next;
790 while (q) {
791 qnext = q->next;
792 if (!rfc_casecmp(q->extra, host)) {
793 if (qprev)
794 qprev->next = q->next;
795 else if (e) {
796 e->u.extra = q->next;
797 qprev = NULL;
798 }
799 nfree(q->extra);
800 nfree(q);
801 i++;
802 } else
803 qprev = q;
804 q = qnext;
805 }
806 }
807 if (!qprev)
808 set_user(&USERENTRY_HOSTS, u, "none");
809 if (!noshare && i && !(u->flags & USER_UNSHARED))
810 shareout(NULL, "-h %s %s\n", handle, host);
811 clear_chanlist();
812 return i;
813 }
814
815 void addhost_by_handle(char *handle, char *host)
816 {
817 struct userrec *u = get_user_by_handle(userlist, handle);
818
819 set_user(&USERENTRY_HOSTS, u, host);
820 /* u will be cached, so really no overhead, even tho this looks dumb: */
821 if ((!noshare) && !(u->flags & USER_UNSHARED)) {
822 if (u->flags & USER_BOT)
823 shareout(NULL, "+bh %s %s\n", handle, host);
824 else
825 shareout(NULL, "+h %s %s\n", handle, host);
826 }
827 clear_chanlist();
828 }
829
830 void touch_laston(struct userrec *u, char *where, time_t timeval)
831 {
832 if (!u)
833 return;
834 if (timeval > 1) {
835 struct laston_info *li =
836 (struct laston_info *) get_user(&USERENTRY_LASTON, u);
837
838 if (!li)
839 li = nmalloc(sizeof(struct laston_info));
840
841 else if (li->lastonplace)
842 nfree(li->lastonplace);
843 li->laston = timeval;
844 if (where) {
845 li->lastonplace = nmalloc(strlen(where) + 1);
846 strcpy(li->lastonplace, where);
847 } else
848 li->lastonplace = NULL;
849 set_user(&USERENTRY_LASTON, u, li);
850 } else if (timeval == 1) {
851 set_user(&USERENTRY_LASTON, u, 0);
852 }
853 }
854
855 /* Go through all channel records and try to find a matching
856 * nick. Will return the user's user record if that is known
857 * to the bot. (Fabian)
858 *
859 * Warning: This is unreliable by concept!
860 */
861 struct userrec *get_user_by_nick(char *nick)
862 {
863 struct chanset_t *chan = chanset;
864 memberlist *m;
865
866 Context;
867 while (chan) {
868 m = chan->channel.member;
869 while (m && m->nick[0]) {
870 if (!rfc_casecmp(nick, m->nick)) {
871 char word[512];
872
873 sprintf(word, "%s!%s", m->nick, m->userhost);
874 /* No need to check the return value ourself */
875 return get_user_by_host(word);;
876 }
877 m = m->next;
878 }
879 chan = chan->next;
880 }
881 /* Sorry, no matches */
882 return NULL;
883 }
884
885 void user_del_chan(char *dname)
886 {
887 struct chanuserrec *ch, *och;
888 struct userrec *u;
889
890 for (u = userlist; u; u = u->next) {
891 ch = u->chanrec;
892 och = NULL;
893 while (ch) {
894 if (!rfc_casecmp(dname, ch->channel)) {
895 if (och)
896 och->next = ch->next;
897 else
898 u->chanrec = ch->next;
899
900 if (ch->info)
901 nfree(ch->info);
902 nfree(ch);
903 break;
904 }
905 och = ch;
906 ch = ch->next;
907 }
908 }
909 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23