2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 use MLDBM qw(DB_File);
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',
58 return if $name =~ /::DESTROY$/;
61 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
63 $self->{$name} = shift;
66 return $self->{$name};
70 # initialise the system
76 confess "need a filename in User" if !$fn;
77 $dbm = tie (%u, MLDBM, $fn, O_CREAT|O_RDWR, 0666) or confess "can't open user file: $fn ($!)";
94 # new - create a new user
101 # $call =~ s/-\d+$//o;
103 confess "can't create existing call $call in User\n!" if $u{$call};
106 $self->{call} = $call;
110 $self->{lang} = $main::lang;
116 # get - get an existing user - this seems to return a different reference everytime it is
124 # $call =~ s/-\d+$//o; # strip ssid
129 # get all callsigns in the database
134 return (sort keys %u);
138 # get an existing either from the channel (if there is one) or from the database
140 # It is important to note that if you have done a get (for the channel say) and you
141 # want access or modify that you must use this call (and you must NOT use get's all
142 # over the place willy nilly!)
149 # $call =~ s/-\d+$//o; # strip ssid
151 my $dxchan = DXChannel->get($call);
152 return $dxchan->user if $dxchan;
163 my $call = $self->{call};
168 # del - delete a user
174 my $call = $self->{call};
179 # close - close down a user
185 $self->{lastin} = time;
190 # return a list of valid elements
199 # return a prompt for a field
204 my ($self, $ele) = @_;
209 # enter an element from input, returns 1 for success
214 my ($self, $ele, $value) = @_;
215 return 0 if (!defined $valid{$ele});
217 return 0 if $value eq "";
218 if ($ele eq 'long') {
219 my ($longd, $longm, $longl) = $value =~ /(\d+) (\d+) ([EWew])/;
220 return 0 if (!$longl || $longd < 0 || $longd > 180 || $longm < 0 || $longm > 59);
221 $longd += ($longm/60);
222 $longd = 0-$longd if (uc $longl) eq 'W';
223 $self->{'long'} = $longd;
225 } elsif ($ele eq 'lat') {
226 my ($latd, $latm, $latl) = $value =~ /(\d+) (\d+) ([NSns])/;
227 return 0 if (!$latl || $latd < 0 || $latd > 90 || $latm < 0 || $latm > 59);
229 $latd = 0-$latd if (uc $latl) eq 'S';
230 $self->{'lat'} = $latd;
232 } elsif ($ele eq 'qra') {
233 $self->{'qra'} = UC $value;
236 $self->{$ele} = $value; # default action
242 # some variable accessors
246 @_ ? $self->{sort} = shift : $self->{sort} ;