2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
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
51 isolate => '9,Isolate network,yesno',
52 wantbeep => '0,Rec Beep,yesno',
53 wantann => '0,Rec Announce,yesno',
54 wantwwv => '0,Rec WWV,yesno',
55 wanttalk => '0,Rec Talk,yesno',
56 wantwx => '0,Rec WX,yesno',
57 wantdx => '0,Rec DX Spots,yesno',
66 return if $name =~ /::DESTROY$/;
69 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
71 $self->{$name} = shift;
73 return $self->{$name};
77 # initialise the system
81 my ($pkg, $fn, $mode) = @_;
83 confess "need a filename in User" if !$fn;
86 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
88 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
107 # new - create a new user
114 # $call =~ s/-\d+$//o;
116 confess "can't create existing call $call in User\n!" if $u{$call};
118 my $self = bless {}, $pkg;
119 $self->{call} = $call;
120 $self->{'sort'} = 'U';
123 $self->{lang} = $main::lang;
124 $u{call} = $self->encode();
129 # get - get an existing user - this seems to return a different reference everytime it is
137 # $call =~ s/-\d+$//o; # strip ssid
139 return $s ? decode($s) : undef;
143 # get all callsigns in the database
148 return (sort keys %u);
152 # get an existing either from the channel (if there is one) or from the database
154 # It is important to note that if you have done a get (for the channel say) and you
155 # want access or modify that you must use this call (and you must NOT use get's all
156 # over the place willy nilly!)
163 # $call =~ s/-\d+$//o; # strip ssid
165 my $dxchan = DXChannel->get($call);
166 return $dxchan->user if $dxchan;
168 return $s ? decode($s) : undef;
178 my $call = $self->{call};
179 $u{$call} = $self->encode();
183 # create a string from a user reference
192 for $f (sort keys %$self) {
193 my $val = $$self{$f};
194 if (ref $val) { # it's an array (we think)
204 $out .= "'$f'=>q{$val},";
207 $out .= " }, 'DXUser')";
212 # create a hash from a string
220 Log('DXUser', $@) if $@;
226 # del - delete a user
232 my $call = $self->{call};
237 # close - close down a user
243 $self->{lastin} = time;
248 # return a list of valid elements
260 # add one or more groups
264 my $ref = $self->{group} || [ 'local' ];
265 $self->{group} = $ref if !$self->{group};
266 push @$ref, @_ if @_;
269 # remove one or more groups
273 my $ref = $self->{group} || [ 'local' ];
276 $self->{group} = $ref if !$self->{group};
278 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
281 # does this thing contain all the groups listed?
285 my $ref = $self->{group};
288 return 0 if !$ref || @_ == 0;
289 return 1 if @$ref == 0 && @_ == 0;
290 for ($n = 0; $n < @_; ) {
293 $n++ if grep $_ eq $a, @_;
299 # simplified group test just for one group
304 my $ref = $self->{group};
307 return grep $_ eq $s, $ref;
310 # set up a default group (only happens for them's that connect direct)
314 $self->{group} = [ 'local' ];
318 # return a prompt for a field
323 my ($self, $ele) = @_;
327 # some variable accessors
331 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
340 return $self->{$n} = shift if @_;
341 return defined $self->{$n} ? $self->{$n} : 1;
346 return _want('beep', @_);
351 return _want('ann', @_);
356 return _want('wwv', @_);
361 return _want('wx', @_);
366 return _want('dx', @_);