2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 use MLDBM qw(DB_File);
19 use vars qw(%u $dbm $filename %valid);
25 # hash of valid elements and a simple prompt
28 alias => '0,Real Callsign',
31 lat => '0,Latitude,slat',
32 long => '0,Longitude,slong',
34 email => '0,E-mail Address',
35 priv => '9,Privilege Level',
36 lastin => '0,Last Time in,cldatetime',
37 passwd => '9,Password',
38 addr => '0,Full Address',
39 sort => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
40 xpert => '0,Expert Status,yesno',
42 node => '0,Last Node',
43 homenode => '0,Home Node',
44 lockout => '9,Locked out?,yesno', # won't let them in at all
45 dxok => '9,DX Spots?,yesno', # accept his dx spots?
46 annok => '9,Announces?,yesno', # accept his announces?
47 reg => '0,Registered?,yesno', # is this user registered?
49 hmsgno => '0,Highest Msgno',
50 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
59 return if $name =~ /::DESTROY$/;
62 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
64 $self->{$name} = shift;
67 return $self->{$name};
71 # initialise the system
77 confess "need a filename in User" if !$fn;
78 $dbm = tie (%u, MLDBM, $fn, O_CREAT|O_RDWR, 0666) or confess "can't open user file: $fn ($!)";
95 # new - create a new user
102 # $call =~ s/-\d+$//o;
104 confess "can't create existing call $call in User\n!" if $u{$call};
107 $self->{call} = $call;
111 $self->{lang} = $main::lang;
117 # get - get an existing user - this seems to return a different reference everytime it is
125 # $call =~ s/-\d+$//o; # strip ssid
130 # get all callsigns in the database
135 return (sort keys %u);
139 # get an existing either from the channel (if there is one) or from the database
141 # It is important to note that if you have done a get (for the channel say) and you
142 # want access or modify that you must use this call (and you must NOT use get's all
143 # over the place willy nilly!)
150 # $call =~ s/-\d+$//o; # strip ssid
152 my $dxchan = DXChannel->get($call);
153 return $dxchan->user if $dxchan;
164 my $call = $self->{call};
169 # del - delete a user
175 my $call = $self->{call};
180 # close - close down a user
186 $self->{lastin} = time;
191 # return a list of valid elements
203 # add one or more groups
207 my $ref = $self->{group} || [ 'local' ];
208 $self->{group} = $ref if !$self->{group};
209 push @$ref, @_ if @_;
212 # remove one or more groups
216 my $ref = $self->{group} || [ 'local' ];
219 $self->{group} = $ref if !$self->{group};
221 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
224 # does this thing contain all the groups listed?
228 my $ref = $self->{group};
231 return 0 if !$ref || @_ == 0;
232 return 1 if @$ref == 0 && @_ == 0;
233 for ($n = 0; $n < @_; ) {
236 $n++ if grep $_ eq $a, @_;
242 # simplified group test just for one group
247 my $ref = $self->{group};
250 return grep $_ eq $s, $ref;
253 # set up a default group (only happens for them's that connect direct)
257 $self->{group} = [ 'local' ];
261 # return a prompt for a field
266 my ($self, $ele) = @_;
270 # some variable accessors
274 @_ ? $self->{sort} = shift : $self->{sort} ;