get all the debugging finally into the debug files when things go wrong
[spider.git] / perl / DXUser.pm
index a9c7ea030177eb75948a2c5954e9242ab121487e..2357ec050d48cb52c1604b41f1a953cc6e3fef93 100644 (file)
@@ -11,9 +11,11 @@ package DXUser;
 require Exporter;
 @ISA = qw(Exporter);
 
+use DXLog;
 use DB_File;
+use Data::Dumper;
 use Fcntl;
-use Carp;
+use DXDebug;
 
 use strict;
 use vars qw(%u $dbm $filename %valid);
@@ -42,13 +44,22 @@ $filename = undef;
                  node => '0,Last Node',
                  homenode => '0,Home Node',
                  lockout => '9,Locked out?,yesno',     # won't let them in at all
-                 dxok => '9,DX Spots?,yesno', # accept his dx spots?
-                 annok => '9,Announces?,yesno', # accept his announces?
+                 dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
+                 annok => '9,Accept Announces?,yesno', # accept his announces?
                  reg => '0,Registered?,yesno', # is this user registered?
                  lang => '0,Language',
                  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',
+                 nopings => '9,Ping Obs Count',
+                 wantlogininfo => '9,Login info req,yesno',
                 );
 
 no strict;
@@ -63,7 +74,6 @@ sub AUTOLOAD
        confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
        if (@_) {
                $self->{$name} = shift;
-               #       $self->put();
        }
        return $self->{$name};
 }
@@ -108,15 +118,15 @@ 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;
        $self->{'sort'} = 'U';
-       $self->{dxok} = 1;
-       $self->{annok} = 1;
+       $self->{dxok} = '1';
+       $self->{annok} = '1';
        $self->{lang} = $main::lang;
-       $u{call} = $self->encode();
+       $self->put;
        return $self;
 }
 
@@ -170,6 +180,7 @@ sub get_current
 sub put
 {
        my $self = shift;
+       confess "Trying to put nothing!" unless $self && ref $self;
        my $call = $self->{call};
        $u{$call} = $self->encode();
 }
@@ -180,27 +191,11 @@ sub put
 sub encode
 {
        my $self = shift;
-       my $out;
-       my $f;
-
-       $out = "bless( { ";
-       for $f (sort keys %$self) {
-               my $val = $$self{$f};
-           if (ref $val) {          # it's an array (we think)
-                       $out .= "'$f'=>[ ";
-                       foreach (@$val) {
-                               my $s = $_;
-                               $out .= "'$s',";
-                       }
-                       $out .= " ],";
-           } else {
-                       $val =~ s/'/\\'/og;
-                       $val =~ s/\@/\\@/og;
-                       $out .= "'$f'=>q{$val},";
-               }
-       }
-       $out .= " }, 'DXUser')";
-       return $out;
+       my $dd = new Data::Dumper([$self]);
+       $dd->Indent(0);
+       $dd->Terse(1);
+    $dd->Quotekeys($] < 5.005 ? 1 : 0);
+       return $dd->Dumpxs;
 }
 
 #
@@ -212,7 +207,8 @@ sub decode
        my $ref;
        $s = '$ref = ' . $s;
        eval $s;
-       confess $@ if $@;
+       Log('DXUser', $@) if $@;
+       $ref = undef if $@;
        return $ref;
 }
 
@@ -324,5 +320,55 @@ sub sort
        my $self = shift;
        @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
 }
+
+# some accessors
+sub _want
+{
+       my $n = shift;
+       my $self = shift;
+       my $val = shift;
+       my $s = "want$n";
+       $self->{$s} = $val if defined $val;
+       return exists $self->{$s} ? $self->{$s} : 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', @_);
+}
+
+sub wantlogininfo
+{
+       my $self = shift;
+       my $n = shift;
+       $self->{wantlogininfo} = $n if $n;
+       return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
+}
+
 1;
 __END__