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