]> git.donarmstrong.com Git - infobot.git/blob - src/User.pl
closed 17225 -- seen only stores addressed messages. Also moved seen code from User...
[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 = $_[0];
10     my ($ret, $f, $o) = "";
11     my @ind = split //, $flags;
12
13     $userHandle ||= "default";
14
15     &DEBUG("isFlag: userHandle == '$userHandle'.");
16
17     foreach $f (split //, $userList{$userHandle}{'flags'}) {
18         foreach $o (@ind) {
19             next unless ($f eq $o);
20
21             $ret = $f;
22             last;
23         }
24     }
25     $ret;
26 }
27
28 sub verifyUser {
29     my ($nick, $lnuh) = @_;
30 #    my ($n,$u,$h) = ($lnuh =~ /^(\S+)!(\S+)\@(\S+)$/);
31     my ($user,$m);
32     $userHandle = "default";
33
34     ### FIXME: THIS NEEDS TO BE FIXED TO RECOGNISE HOSTMASKS!!!
35     my $userinlist = "";
36     foreach $user (keys %userList) {
37         ### Hack for time being.
38         if (0) {
39             if ($user =~ /^\Q$nick\E$/i) {
40                 &DEBUG("vU: setting uH => '$user'.");
41                 $userHandle = $user;
42                 last;
43             }
44             next;
45         } else {
46             $userinlist = $user if ($user =~ /^\Q$nick\E$/);
47         }
48
49         foreach $m (keys %{$userList{$user}{'mask'}}) {
50             $m =~ s/\?/./g;
51             $m =~ s/\*/.*?/g;
52             $m =~ s/([\@\(\)\[\]])/\\$1/g;
53
54             next unless ($lnuh =~ /^$m$/i);
55             &DEBUG("vUser: $lnuh matched masked ($m). Good!");
56
57             $userHandle = $user;
58             $userinlist = "";
59             last;
60         }
61         last if ($userHandle ne "");
62     }
63
64     if ($userinlist and $userHandle eq "") {
65         &DEBUG("vUser: user is in list but wrong host.");
66         $userHandle = $userinlist;
67     }
68
69 #    $talkWho{$talkchannel} = $orig{who};
70 #    $talkWho = $orig{who};
71 ### FIXME HERE.
72     $talkWho{$talkchannel} = $who if (defined $talkchannel);
73     $talkWho = $who;
74
75     return $userHandle;
76 }
77
78 sub ckpasswd {
79     # returns true if arg1 encrypts to arg2
80     my ($plain, $encrypted) = @_;
81     if ($encrypted eq "") {
82         ($plain, $encrypted) = split(/\s+/, $plain, 2);
83     }
84     return 0 unless ($plain ne "" and $encrypted ne "");
85
86     # MD5 // DES. Bobby Billingsley++.
87     my $salt = substr($encrypted, 0, 2);
88     if ($encrypted =~ /^\$\d\$(\w\w)\$/) {
89         $salt = $1;
90     }
91
92     return ($encrypted eq crypt($plain, $salt));
93 }
94
95 # mainly for dcc chat... hrm.
96 sub hasFlag {
97     my ($flag) = @_;
98
99     if (&IsFlag($flag) eq $flag) {
100         return 1;
101     } else {
102         &status("DCC CHAT: <$who> $message -- not enough flags.");
103         &performStrictReply("error: you do not have enough flags for that. ($flag required)");
104         return 0;
105     }
106 }
107
108 1;