2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
20 use vars qw(%u $dbm $filename %valid);
26 # hash of valid elements and a simple prompt
29 alias => '0,Real Callsign',
32 lat => '0,Latitude,slat',
33 long => '0,Longitude,slong',
35 email => '0,E-mail Address',
36 priv => '9,Privilege Level',
37 lastin => '0,Last Time in,cldatetime',
38 passwd => '9,Password',
39 addr => '0,Full Address',
40 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
41 xpert => '0,Expert Status,yesno',
43 node => '0,Last Node',
44 homenode => '0,Home Node',
45 lockout => '9,Locked out?,yesno', # won't let them in at all
46 dxok => '9,DX Spots?,yesno', # accept his dx spots?
47 annok => '9,Announces?,yesno', # accept his announces?
48 reg => '0,Registered?,yesno', # is this user registered?
50 hmsgno => '0,Highest Msgno',
51 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
52 isolate => '9,Isolate network,yesno',
53 wantbeep => '0,Rec Beep,yesno',
54 wantann => '0,Rec Announce,yesno',
55 wantwwv => '0,Rec WWV,yesno',
56 wanttalk => '0,Rec Talk,yesno',
57 wantwx => '0,Rec WX,yesno',
58 wantdx => '0,Rec DX Spots,yesno',
67 return if $name =~ /::DESTROY$/;
70 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
72 $self->{$name} = shift;
74 return $self->{$name};
78 # initialise the system
82 my ($pkg, $fn, $mode) = @_;
84 confess "need a filename in User" if !$fn;
87 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
89 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
108 # new - create a new user
115 # $call =~ s/-\d+$//o;
117 # confess "can't create existing call $call in User\n!" if $u{$call};
119 my $self = bless {}, $pkg;
120 $self->{call} = $call;
121 $self->{'sort'} = 'U';
124 $self->{lang} = $main::lang;
125 $u{call} = $self->encode();
130 # get - get an existing user - this seems to return a different reference everytime it is
138 # $call =~ s/-\d+$//o; # strip ssid
140 return $s ? decode($s) : undef;
144 # get all callsigns in the database
149 return (sort keys %u);
153 # get an existing either from the channel (if there is one) or from the database
155 # It is important to note that if you have done a get (for the channel say) and you
156 # want access or modify that you must use this call (and you must NOT use get's all
157 # over the place willy nilly!)
164 # $call =~ s/-\d+$//o; # strip ssid
166 my $dxchan = DXChannel->get($call);
167 return $dxchan->user if $dxchan;
169 return $s ? decode($s) : undef;
179 my $call = $self->{call};
180 $u{$call} = $self->encode();
184 # create a string from a user reference
193 for $f (sort keys %$self) {
194 my $val = $$self{$f};
195 if (ref $val) { # it's an array (we think)
205 $out .= "'$f'=>q{$val},";
208 $out .= " }, 'DXUser')";
213 # create a hash from a string
221 Log('DXUser', $@) if $@;
227 # del - delete a user
233 my $call = $self->{call};
238 # close - close down a user
244 $self->{lastin} = time;
249 # return a list of valid elements
261 # add one or more groups
265 my $ref = $self->{group} || [ 'local' ];
266 $self->{group} = $ref if !$self->{group};
267 push @$ref, @_ if @_;
270 # remove one or more groups
274 my $ref = $self->{group} || [ 'local' ];
277 $self->{group} = $ref if !$self->{group};
279 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
282 # does this thing contain all the groups listed?
286 my $ref = $self->{group};
289 return 0 if !$ref || @_ == 0;
290 return 1 if @$ref == 0 && @_ == 0;
291 for ($n = 0; $n < @_; ) {
294 $n++ if grep $_ eq $a, @_;
300 # simplified group test just for one group
305 my $ref = $self->{group};
308 return grep $_ eq $s, $ref;
311 # set up a default group (only happens for them's that connect direct)
315 $self->{group} = [ 'local' ];
319 # return a prompt for a field
324 my ($self, $ele) = @_;
328 # some variable accessors
332 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
341 return $self->{$n} = shift if @_;
342 return defined $self->{$n} ? $self->{$n} : 1;
347 return _want('beep', @_);
352 return _want('ann', @_);
357 return _want('wwv', @_);
362 return _want('wx', @_);
367 return _want('dx', @_);