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,DX Spots?,yesno', # accept his dx spots?
48 annok => '9,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',
69 return if $name =~ /::DESTROY$/;
72 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
74 $self->{$name} = shift;
76 return $self->{$name};
80 # initialise the system
84 my ($pkg, $fn, $mode) = @_;
86 confess "need a filename in User" if !$fn;
89 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
91 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
110 # new - create a new user
117 # $call =~ s/-\d+$//o;
119 # confess "can't create existing call $call in User\n!" if $u{$call};
121 my $self = bless {}, $pkg;
122 $self->{call} = $call;
123 $self->{'sort'} = 'U';
126 $self->{lang} = $main::lang;
132 # get - get an existing user - this seems to return a different reference everytime it is
140 # $call =~ s/-\d+$//o; # strip ssid
142 return $s ? decode($s) : undef;
146 # get all callsigns in the database
151 return (sort keys %u);
155 # get an existing either from the channel (if there is one) or from the database
157 # It is important to note that if you have done a get (for the channel say) and you
158 # want access or modify that you must use this call (and you must NOT use get's all
159 # over the place willy nilly!)
166 # $call =~ s/-\d+$//o; # strip ssid
168 my $dxchan = DXChannel->get($call);
169 return $dxchan->user if $dxchan;
171 return $s ? decode($s) : undef;
181 confess "Trying to put nothing!" unless $self && ref $self;
182 my $call = $self->{call};
183 $u{$call} = $self->encode();
187 # create a string from a user reference
192 my $dd = new Data::Dumper([$self]);
200 # create a hash from a string
208 Log('DXUser', $@) if $@;
214 # del - delete a user
220 my $call = $self->{call};
225 # close - close down a user
231 $self->{lastin} = time;
236 # return a list of valid elements
248 # add one or more groups
252 my $ref = $self->{group} || [ 'local' ];
253 $self->{group} = $ref if !$self->{group};
254 push @$ref, @_ if @_;
257 # remove one or more groups
261 my $ref = $self->{group} || [ 'local' ];
264 $self->{group} = $ref if !$self->{group};
266 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
269 # does this thing contain all the groups listed?
273 my $ref = $self->{group};
276 return 0 if !$ref || @_ == 0;
277 return 1 if @$ref == 0 && @_ == 0;
278 for ($n = 0; $n < @_; ) {
281 $n++ if grep $_ eq $a, @_;
287 # simplified group test just for one group
292 my $ref = $self->{group};
295 return grep $_ eq $s, $ref;
298 # set up a default group (only happens for them's that connect direct)
302 $self->{group} = [ 'local' ];
306 # return a prompt for a field
311 my ($self, $ele) = @_;
315 # some variable accessors
319 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
328 return $self->{$n} = shift if @_;
329 return defined $self->{$n} ? $self->{$n} : 1;
334 return _want('beep', @_);
339 return _want('ann', @_);
344 return _want('wwv', @_);
349 return _want('wx', @_);
354 return _want('dx', @_);
359 return _want('talk', @_);