]> git.donarmstrong.com Git - infobot.git/blob - src/User.pl
- unified hook changes.
[infobot.git] / src / User.pl
1 #
2 # originally by kevin lenzo.
3 # revamped by the xk.
4 #
5
6 if (&IsParam("useStrict")) { use strict; }
7
8 sub IsFlag {
9     my $flags = shift;
10     my ($ret, $f, $o) = "";
11
12     foreach $f (split //, $userList{$userHandle}{'flags'}) {
13         foreach $o ( split //, $flags ) {
14             next unless ($f eq $o);
15
16             $ret = $f;
17             last;
18         }
19     }
20
21     $ret;
22 }
23
24 sub verifyUser {
25     my ($nick, $lnuh) = @_;
26     my ($user,$m);
27
28     $userHandle = "";
29
30     foreach $user (keys %userList) {
31         foreach $m (keys %{$userList{$user}{'mask'}}) {
32             $m =~ s/\?/./g;
33             $m =~ s/\*/.*?/g;
34             $m =~ s/([\@\(\)\[\]])/\\$1/g;
35
36             next unless ($lnuh =~ /^$m$/i);
37
38             if ($user !~ /^\Q$nick\E$/i) {
39                 &status("vU: host matched but diff nick ($nick != $user).");
40             }
41
42             $userHandle = $user;
43             last;
44         }
45
46         last if ($userHandle ne "");
47
48         if ($user =~ /^\Q$nick\E$/i) {
49             &status("vU: nick matched but host is not in list ($lnuh).");
50         }
51     }
52
53     $userHandle ||= "default";
54     $talkWho{$talkchannel} = $who if (defined $talkchannel);
55     $talkWho = $who;
56
57     return $userHandle;
58 }
59
60 sub ckpasswd {
61     # returns true if arg1 encrypts to arg2
62     my ($plain, $encrypted) = @_;
63     if ($encrypted eq "") {
64         ($plain, $encrypted) = split(/\s+/, $plain, 2);
65     }
66     return 0 unless ($plain ne "" and $encrypted ne "");
67
68     # MD5 // DES. Bobby Billingsley++.
69     my $salt = substr($encrypted, 0, 2);
70     if ($encrypted =~ /^\$\d\$(\w\w)\$/) {
71         $salt = $1;
72     }
73
74     return ($encrypted eq crypt($plain, $salt));
75 }
76
77 # mainly for dcc chat... hrm.
78 sub hasFlag {
79     my ($flag) = @_;
80
81     if (&IsFlag($flag) eq $flag) {
82         return 1;
83     } else {
84         &status("DCC CHAT: <$who> $message -- not enough flags.");
85         &performStrictReply("error: you do not have enough flags for that. ($flag required)");
86         return 0;
87     }
88 }
89
90 1;