X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=9d534ae9d1835f6b2eaaeb4ab6b0fc33a2378260;hb=8ebfb28af6e8ec81acbd7de0f5e19fab4c32a8b6;hp=810bb7682d85c7f752249b013b2ef8ff3909fc81;hpb=584783d0ee480f9f56c167fc2e2aec280ba5e897;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 810bb768..9d534ae9 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -11,7 +11,9 @@ package DXUser; require Exporter; @ISA = qw(Exporter); -use MLDBM qw(DB_File); +use DXLog; +use DB_File; +use Data::Dumper; use Fcntl; use Carp; @@ -49,6 +51,13 @@ $filename = undef; hmsgno => '0,Highest Msgno', group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other isolate => '9,Isolate network,yesno', + wantbeep => '0,Rec Beep,yesno', + wantann => '0,Rec Announce,yesno', + wantwwv => '0,Rec WWV,yesno', + wanttalk => '0,Rec Talk,yesno', + wantwx => '0,Rec WX,yesno', + wantdx => '0,Rec DX Spots,yesno', + pingint => '9,Node Ping interval', ); no strict; @@ -63,7 +72,6 @@ sub AUTOLOAD confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; if (@_) { $self->{$name} = shift; - # $self->put(); } return $self->{$name}; } @@ -73,10 +81,16 @@ sub AUTOLOAD # sub init { - my ($pkg, $fn) = @_; + my ($pkg, $fn, $mode) = @_; confess "need a filename in User" if !$fn; - $dbm = tie (%u, MLDBM, $fn, O_CREAT|O_RDWR, 0666) or confess "can't open user file: $fn ($!)"; + $fn .= ".v2"; + if ($mode) { + $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)"; + } else { + $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)"; + } + $filename = $fn; } @@ -88,7 +102,7 @@ use strict; sub finish { - $dbm = undef; + undef $dbm; untie %u; } @@ -102,7 +116,7 @@ sub new my $call = uc shift; # $call =~ s/-\d+$//o; - confess "can't create existing call $call in User\n!" if $u{$call}; +# confess "can't create existing call $call in User\n!" if $u{$call}; my $self = bless {}, $pkg; $self->{call} = $call; @@ -110,7 +124,7 @@ sub new $self->{dxok} = 1; $self->{annok} = 1; $self->{lang} = $main::lang; - $u{call} = $self; + $self->put; return $self; } @@ -124,7 +138,8 @@ sub get my $pkg = shift; my $call = uc shift; # $call =~ s/-\d+$//o; # strip ssid - return $u{$call}; + my $s = $u{$call}; + return $s ? decode($s) : undef; } # @@ -152,7 +167,8 @@ sub get_current my $dxchan = DXChannel->get($call); return $dxchan->user if $dxchan; - return $u{$call}; + my $s = $u{$call}; + return $s ? decode($s) : undef; } # @@ -162,8 +178,36 @@ sub get_current sub put { my $self = shift; + confess "Trying to put nothing!" unless $self && ref $self; my $call = $self->{call}; - $u{$call} = $self; + $u{$call} = $self->encode(); +} + +# +# create a string from a user reference +# +sub encode +{ + my $self = shift; + my $dd = new Data::Dumper([$self]); + $dd->Indent(0); + $dd->Terse(1); + $dd->Quotekeys($] < 5.005 ? 1 : 0); + return $dd->Dumpxs; +} + +# +# create a hash from a string +# +sub decode +{ + my $s = shift; + my $ref; + $s = '$ref = ' . $s; + eval $s; + Log('DXUser', $@) if $@; + $ref = undef if $@; + return $ref; } # @@ -274,5 +318,46 @@ sub sort my $self = shift; @_ ? $self->{'sort'} = shift : $self->{'sort'} ; } + +# some accessors +sub _want +{ + my $n = shift; + my $self = shift; + my $s = "want$n"; + return $self->{$n} = shift if @_; + return defined $self->{$n} ? $self->{$n} : 1; +} + +sub wantbeep +{ + return _want('beep', @_); +} + +sub wantann +{ + return _want('ann', @_); +} + +sub wantwwv +{ + return _want('wwv', @_); +} + +sub wantwx +{ + return _want('wx', @_); +} + +sub wantdx +{ + return _want('dx', @_); +} + +sub wanttalk +{ + return _want('talk', @_); +} + 1; __END__