/[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.30 - (show annotations) (download) (as text)
Thu Apr 12 02:39:44 2001 UTC (18 years, 9 months ago) by guppy
Branch: MAIN
Changes since 1.29: +22 -22 lines
File MIME type: text/x-chdr
lets update the copyright info for 2001 k? :P~

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23