]> git.donarmstrong.com Git - infobot.git/blob - src/User.pl
Initial revision
[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     # seen.
70     if (&IsParam("seen") and $msgType =~ /public/) {
71         $seencache{$who}{'time'} = time();
72         $seencache{$who}{'nick'} = $orig{who};
73         $seencache{$who}{'host'} = $uh;
74         $seencache{$who}{'chan'} = $talkchannel;
75         $seencache{$who}{'msg'}  = $orig{message};
76         $seencache{$who}{'msgcount'}++;
77     }
78
79 #    $talkWho{$talkchannel} = $orig{who};
80 #    $talkWho = $orig{who};
81 ### FIXME HERE.
82     $talkWho{$talkchannel} = $who if (defined $talkchannel);
83     $talkWho = $who;
84
85     return $userHandle;
86 }
87
88 sub ckpasswd {
89     # returns true if arg1 encrypts to arg2
90     my ($plain, $encrypted) = @_;
91     if ($encrypted eq "") {
92         ($plain, $encrypted) = split(/\s+/, $plain, 2);
93     }
94     return 0 unless ($plain ne "" and $encrypted ne "");
95
96     # MD5 // DES. Bobby Billingsley++.
97     my $salt = substr($encrypted, 0, 2);
98     if ($encrypted =~ /^\$\d\$(\w\w)\$/) {
99         $salt = $1;
100     }
101
102     return ($encrypted eq crypt($plain, $salt));
103 }
104
105 # mainly for dcc chat... hrm.
106 sub hasFlag {
107     my ($flag) = @_;
108
109     if (&IsFlag($flag) eq $flag) {
110         return 1;
111     } else {
112         &status("DCC CHAT: <$who> $message -- not enough flags.");
113         &performStrictReply("error: you do not have enough flags for that. ($flag required)");
114         return 0;
115     }
116 }
117
118 1;