/[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.12 - (show annotations) (download) (as text)
Thu Jan 6 19:45:03 2000 UTC (20 years ago) by fabian
Branch: MAIN
Changes since 1.11: +4 -3 lines
File MIME type: text/x-chdr
errors_fix, simialer to 1.4

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23