2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw(%u $dbm $filename %valid);
27 # hash of valid elements and a simple prompt
30 alias => '0,Real Callsign',
33 lat => '0,Latitude,slat',
34 long => '0,Longitude,slong',
36 email => '0,E-mail Address',
37 priv => '9,Privilege Level',
38 lastin => '0,Last Time in,cldatetime',
39 passwd => '9,Password',
40 addr => '0,Full Address',
41 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
42 xpert => '0,Expert Status,yesno',
44 node => '0,Last Node',
45 homenode => '0,Home Node',
46 lockout => '9,Locked out?,yesno', # won't let them in at all
47 dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
48 annok => '9,Accept Announces?,yesno', # accept his announces?
49 reg => '0,Registered?,yesno', # is this user registered?
51 hmsgno => '0,Highest Msgno',
52 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
53 isolate => '9,Isolate network,yesno',
54 wantbeep => '0,Rec Beep,yesno',
55 wantann => '0,Rec Announce,yesno',
56 wantwwv => '0,Rec WWV,yesno',
57 wanttalk => '0,Rec Talk,yesno',
58 wantwx => '0,Rec WX,yesno',
59 wantdx => '0,Rec DX Spots,yesno',
60 pingint => '9,Node Ping interval',
61 nopings => '9,Ping Obs Count',
62 wantlogininfo => '9,Login info req,yesno',
71 return if $name =~ /::DESTROY$/;
74 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
76 $self->{$name} = shift;
78 return $self->{$name};
82 # initialise the system
86 my ($pkg, $fn, $mode) = @_;
88 confess "need a filename in User" if !$fn;
91 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
93 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
112 # new - create a new user
119 # $call =~ s/-\d+$//o;
121 # confess "can't create existing call $call in User\n!" if $u{$call};
123 my $self = bless {}, $pkg;
124 $self->{call} = $call;
125 $self->{'sort'} = 'U';
127 $self->{annok} = '1';
128 $self->{lang} = $main::lang;
134 # get - get an existing user - this seems to return a different reference everytime it is
142 # $call =~ s/-\d+$//o; # strip ssid
144 return $s ? decode($s) : undef;
148 # get all callsigns in the database
153 return (sort keys %u);
157 # get an existing either from the channel (if there is one) or from the database
159 # It is important to note that if you have done a get (for the channel say) and you
160 # want access or modify that you must use this call (and you must NOT use get's all
161 # over the place willy nilly!)
168 # $call =~ s/-\d+$//o; # strip ssid
170 my $dxchan = DXChannel->get($call);
171 return $dxchan->user if $dxchan;
173 return $s ? decode($s) : undef;
183 confess "Trying to put nothing!" unless $self && ref $self;
184 my $call = $self->{call};
185 $u{$call} = $self->encode();
189 # create a string from a user reference
194 my $dd = new Data::Dumper([$self]);
197 $dd->Quotekeys($] < 5.005 ? 1 : 0);
202 # create a hash from a string
210 Log('DXUser', $@) if $@;
216 # del - delete a user
222 my $call = $self->{call};
227 # close - close down a user
233 $self->{lastin} = time;
238 # return a list of valid elements
250 # add one or more groups
254 my $ref = $self->{group} || [ 'local' ];
255 $self->{group} = $ref if !$self->{group};
256 push @$ref, @_ if @_;
259 # remove one or more groups
263 my $ref = $self->{group} || [ 'local' ];
266 $self->{group} = $ref if !$self->{group};
268 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
271 # does this thing contain all the groups listed?
275 my $ref = $self->{group};
278 return 0 if !$ref || @_ == 0;
279 return 1 if @$ref == 0 && @_ == 0;
280 for ($n = 0; $n < @_; ) {
283 $n++ if grep $_ eq $a, @_;
289 # simplified group test just for one group
294 my $ref = $self->{group};
297 return grep $_ eq $s, $ref;
300 # set up a default group (only happens for them's that connect direct)
304 $self->{group} = [ 'local' ];
308 # return a prompt for a field
313 my ($self, $ele) = @_;
317 # some variable accessors
321 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
331 $self->{$s} = $val if defined $val;
332 return exists $self->{$s} ? $self->{$s} : 1;
337 return _want('beep', @_);
342 return _want('ann', @_);
347 return _want('wwv', @_);
352 return _want('wx', @_);
357 return _want('dx', @_);
362 return _want('talk', @_);
369 $self->{wantlogininfo} = $n if $n;
370 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;