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 wantwcy => '0,Rec WCY,yesno',
58 wantecho => '0,Rec Echo,yesno',
59 wanttalk => '0,Rec Talk,yesno',
60 wantwx => '0,Rec WX,yesno',
61 wantdx => '0,Rec DX Spots,yesno',
62 pagelth => '0,Current Pagelth',
63 pingint => '9,Node Ping interval',
64 nopings => '9,Ping Obs Count',
65 wantlogininfo => '9,Login info req,yesno',
74 return if $name =~ /::DESTROY$/;
77 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
79 $self->{$name} = shift;
81 return $self->{$name};
85 # initialise the system
89 my ($pkg, $fn, $mode) = @_;
91 confess "need a filename in User" if !$fn;
94 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
96 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
115 # new - create a new user
122 # $call =~ s/-\d+$//o;
124 # confess "can't create existing call $call in User\n!" if $u{$call};
126 my $self = bless {}, $pkg;
127 $self->{call} = $call;
128 $self->{'sort'} = 'U';
130 $self->{annok} = '1';
131 $self->{lang} = $main::lang;
137 # get - get an existing user - this seems to return a different reference everytime it is
145 # $call =~ s/-\d+$//o; # strip ssid
147 return $s ? decode($s) : undef;
151 # get all callsigns in the database
156 return (sort keys %u);
160 # get an existing either from the channel (if there is one) or from the database
162 # It is important to note that if you have done a get (for the channel say) and you
163 # want access or modify that you must use this call (and you must NOT use get's all
164 # over the place willy nilly!)
171 # $call =~ s/-\d+$//o; # strip ssid
173 my $dxchan = DXChannel->get($call);
174 return $dxchan->user if $dxchan;
176 return $s ? decode($s) : undef;
186 confess "Trying to put nothing!" unless $self && ref $self;
187 my $call = $self->{call};
188 $u{$call} = $self->encode();
192 # create a string from a user reference
197 my $dd = new Data::Dumper([$self]);
200 $dd->Quotekeys($] < 5.005 ? 1 : 0);
205 # create a hash from a string
213 Log('DXUser', $@) if $@;
219 # del - delete a user
225 my $call = $self->{call};
230 # close - close down a user
236 $self->{lastin} = time;
241 # return a list of valid elements
253 # add one or more groups
257 my $ref = $self->{group} || [ 'local' ];
258 $self->{group} = $ref if !$self->{group};
259 push @$ref, @_ if @_;
262 # remove one or more groups
266 my $ref = $self->{group} || [ 'local' ];
269 $self->{group} = $ref if !$self->{group};
271 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
274 # does this thing contain all the groups listed?
278 my $ref = $self->{group};
281 return 0 if !$ref || @_ == 0;
282 return 1 if @$ref == 0 && @_ == 0;
283 for ($n = 0; $n < @_; ) {
286 $n++ if grep $_ eq $a, @_;
292 # simplified group test just for one group
297 my $ref = $self->{group};
300 return grep $_ eq $s, $ref;
303 # set up a default group (only happens for them's that connect direct)
307 $self->{group} = [ 'local' ];
311 # return a prompt for a field
316 my ($self, $ele) = @_;
320 # some variable accessors
324 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
334 $self->{$s} = $val if defined $val;
335 return exists $self->{$s} ? $self->{$s} : 1;
340 return _want('beep', @_);
345 return _want('ann', @_);
350 return _want('wwv', @_);
355 return _want('wcy', @_);
360 return _want('echo', @_);
365 return _want('wx', @_);
370 return _want('dx', @_);
375 return _want('talk', @_);
382 $self->{wantlogininfo} = $n if $n;
383 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
389 return $self->{sort} =~ /[ACRSX]/;
395 return $self->{sort} eq 'U';
401 return $self->{sort} eq 'B';
407 return $self->{sort} eq 'S';
413 return $self->{sort} eq 'C';
419 return $self->{sort} eq 'X';
425 return $self->{sort} eq 'R';
431 return $self->{sort} eq 'A';