/[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.22 - (show annotations) (download) (as text)
Mon Aug 7 10:09:53 2000 UTC (19 years, 5 months ago) by fabian
Branch: MAIN
CVS Tags: eggdrop105040
Changes since 1.21: +2 -2 lines
File MIME type: text/x-chdr
Sup's handlechg 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.21 2000/08/06 14:48:01 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[HANDLEN + 1];
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 strncpy(s, u->handle, HANDLEN);
601 s[HANDLEN] = 0;
602 strncpy(u->handle, newh, HANDLEN);
603 u->handle[HANDLEN] = 0;
604 for (i = 0; i < dcc_total; i++)
605 if (!egg_strcasecmp(dcc[i].nick, s) && dcc[i].type != &DCC_BOT) {
606 strncpy(dcc[i].nick, newh, HANDLEN);
607 dcc[i].nick[HANDLEN] = 0;
608 if (dcc[i].type == &DCC_CHAT && dcc[i].u.chat->channel >= 0) {
609 chanout_but(-1, dcc[i].u.chat->channel,
610 "*** Handle change: %s -> %s\n", s, newh);
611 if (dcc[i].u.chat->channel < 100000)
612 botnet_send_nkch(i, s);
613 }
614 }
615 return 1;
616 }
617
618 extern int noxtra;
619
620 struct userrec *adduser(struct userrec *bu, char *handle, char *host,
621 char *pass, int flags)
622 {
623 struct userrec *u, *x;
624 struct xtra_key *xk;
625 int oldshare = noshare;
626
627 noshare = 1;
628 u = (struct userrec *) nmalloc(sizeof(struct userrec));
629
630 /* u->next=bu; bu=u; */
631 strncpy(u->handle, handle, HANDLEN);
632 u->handle[HANDLEN] = 0;
633 u->next = NULL;
634 u->chanrec = NULL;
635 u->entries = NULL;
636 if (flags != USER_DEFAULT) { /* drummer */
637 u->flags = flags;
638 u->flags_udef = 0;
639 } else {
640 u->flags = default_flags;
641 u->flags_udef = default_uflags;
642 }
643 set_user(&USERENTRY_PASS, u, pass);
644 if (!noxtra) {
645 xk = nmalloc(sizeof(struct xtra_key));
646
647 xk->key = nmalloc(8);
648 strcpy(xk->key, "created");
649 xk->data = nmalloc(10);
650 sprintf(xk->data, "%09lu", now);
651 set_user(&USERENTRY_XTRA, u, xk);
652 }
653 /* Strip out commas -- they're illegal */
654 if (host && host[0]) {
655 char *p;
656
657 /* About this fixfrom():
658 * We should use this fixfrom before every call of adduser()
659 * but its much easier to use here... (drummer)
660 * Only use it if we have a host :) (dw)
661 */
662 host = fixfrom(host);
663 p = strchr(host, ',');
664
665 while (p != NULL) {
666 *p = '?';
667 p = strchr(host, ',');
668 }
669 set_user(&USERENTRY_HOSTS, u, host);
670 } else
671 set_user(&USERENTRY_HOSTS, u, "none");
672 if (bu == userlist)
673 clear_chanlist();
674 noshare = oldshare;
675 if ((!noshare) && (handle[0] != '*') && (!(flags & USER_UNSHARED)) &&
676 (bu == userlist)) {
677 struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
678 char x[100];
679
680 fr.global = u->flags;
681 fr.udef_global = u->flags_udef;
682 build_flags(x, &fr, 0);
683 shareout(NULL, "n %s %s %s %s\n", handle, host && host[0] ? host : "none",
684 pass, x);
685 }
686 if (bu == NULL)
687 bu = u;
688 else {
689 if ((bu == userlist) && (lastuser != NULL))
690 x = lastuser;
691 else
692 x = bu;
693 while (x->next != NULL)
694 x = x->next;
695 x->next = u;
696 if (bu == userlist)
697 lastuser = u;
698 }
699 return bu;
700 }
701
702 void freeuser(struct userrec *u)
703 {
704 struct user_entry *ue, *ut;
705 struct chanuserrec *ch, *z;
706
707 if (u == NULL)
708 return;
709 ch = u->chanrec;
710 while (ch) {
711 z = ch;
712 ch = ch->next;
713 if (z->info != NULL)
714 nfree(z->info);
715 nfree(z);
716 }
717 u->chanrec = NULL;
718 for (ue = u->entries; ue; ue = ut) {
719 ut = ue->next;
720 if (ue->name) {
721 struct list_type *lt, *ltt;
722
723 for (lt = ue->u.list; lt; lt = ltt) {
724 ltt = lt->next;
725 nfree(lt->extra);
726 nfree(lt);
727 }
728 nfree(ue->name);
729 nfree(ue);
730 } else {
731 ue->type->kill(ue);
732 }
733 }
734 nfree(u);
735 }
736
737 int deluser(char *handle)
738 {
739 struct userrec *u = userlist, *prev = NULL;
740 int fnd = 0;
741
742 while ((u != NULL) && (!fnd)) {
743 if (!egg_strcasecmp(u->handle, handle))
744 fnd = 1;
745 else {
746 prev = u;
747 u = u->next;
748 }
749 }
750 if (!fnd)
751 return 0;
752 if (prev == NULL)
753 userlist = u->next;
754 else
755 prev->next = u->next;
756 if (!noshare && (handle[0] != '*') && !(u->flags & USER_UNSHARED))
757 shareout(NULL, "k %s\n", handle);
758 for (fnd = 0; fnd < dcc_total; fnd++)
759 if (dcc[fnd].user == u)
760 dcc[fnd].user = 0; /* Clear any dcc users for this entry,
761 * null is safe-ish */
762 clear_chanlist();
763 freeuser(u);
764 lastuser = NULL;
765 return 1;
766 }
767
768 int delhost_by_handle(char *handle, char *host)
769 {
770 struct userrec *u;
771 struct list_type *q, *qnext, *qprev;
772 struct user_entry *e = NULL;
773 int i = 0;
774
775 Context;
776 u = get_user_by_handle(userlist, handle);
777 if (!u)
778 return 0;
779 q = get_user(&USERENTRY_HOSTS, u);
780 qprev = q;
781 if (q) {
782 if (!rfc_casecmp(q->extra, host)) {
783 e = find_user_entry(&USERENTRY_HOSTS, u);
784 e->u.extra = q->next;
785 nfree(q->extra);
786 nfree(q);
787 i++;
788 qprev = NULL;
789 q = e->u.extra;
790 } else
791 q = q->next;
792 while (q) {
793 qnext = q->next;
794 if (!rfc_casecmp(q->extra, host)) {
795 if (qprev)
796 qprev->next = q->next;
797 else if (e) {
798 e->u.extra = q->next;
799 qprev = NULL;
800 }
801 nfree(q->extra);
802 nfree(q);
803 i++;
804 } else
805 qprev = q;
806 q = qnext;
807 }
808 }
809 if (!qprev)
810 set_user(&USERENTRY_HOSTS, u, "none");
811 if (!noshare && i && !(u->flags & USER_UNSHARED))
812 shareout(NULL, "-h %s %s\n", handle, host);
813 clear_chanlist();
814 return i;
815 }
816
817 void addhost_by_handle(char *handle, char *host)
818 {
819 struct userrec *u = get_user_by_handle(userlist, handle);
820
821 set_user(&USERENTRY_HOSTS, u, host);
822 /* u will be cached, so really no overhead, even tho this looks dumb: */
823 if ((!noshare) && !(u->flags & USER_UNSHARED)) {
824 if (u->flags & USER_BOT)
825 shareout(NULL, "+bh %s %s\n", handle, host);
826 else
827 shareout(NULL, "+h %s %s\n", handle, host);
828 }
829 clear_chanlist();
830 }
831
832 void touch_laston(struct userrec *u, char *where, time_t timeval)
833 {
834 if (!u)
835 return;
836 if (timeval > 1) {
837 struct laston_info *li =
838 (struct laston_info *) get_user(&USERENTRY_LASTON, u);
839
840 if (!li)
841 li = nmalloc(sizeof(struct laston_info));
842
843 else if (li->lastonplace)
844 nfree(li->lastonplace);
845 li->laston = timeval;
846 if (where) {
847 li->lastonplace = nmalloc(strlen(where) + 1);
848 strcpy(li->lastonplace, where);
849 } else
850 li->lastonplace = NULL;
851 set_user(&USERENTRY_LASTON, u, li);
852 } else if (timeval == 1) {
853 set_user(&USERENTRY_LASTON, u, 0);
854 }
855 }
856
857 /* Go through all channel records and try to find a matching
858 * nick. Will return the user's user record if that is known
859 * to the bot. (Fabian)
860 *
861 * Warning: This is unreliable by concept!
862 */
863 struct userrec *get_user_by_nick(char *nick)
864 {
865 struct chanset_t *chan = chanset;
866 memberlist *m;
867
868 Context;
869 while (chan) {
870 m = chan->channel.member;
871 while (m && m->nick[0]) {
872 if (!rfc_casecmp(nick, m->nick)) {
873 char word[512];
874
875 sprintf(word, "%s!%s", m->nick, m->userhost);
876 /* No need to check the return value ourself */
877 return get_user_by_host(word);;
878 }
879 m = m->next;
880 }
881 chan = chan->next;
882 }
883 /* Sorry, no matches */
884 return NULL;
885 }
886
887 void user_del_chan(char *dname)
888 {
889 struct chanuserrec *ch, *och;
890 struct userrec *u;
891
892 for (u = userlist; u; u = u->next) {
893 ch = u->chanrec;
894 och = NULL;
895 while (ch) {
896 if (!rfc_casecmp(dname, ch->channel)) {
897 if (och)
898 och->next = ch->next;
899 else
900 u->chanrec = ch->next;
901
902 if (ch->info)
903 nfree(ch->info);
904 nfree(ch);
905 break;
906 }
907 och = ch;
908 ch = ch->next;
909 }
910 }
911 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23