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

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

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


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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23