X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=4994c4e0b0e4c6fbabae178740f4eaf91143e7f5;hb=bd8b8aa6d37a7dde70d093c5552c29f519ac9613;hp=02ed86cd002949b5d94c8f74def12ccd1e8d3db9;hpb=6ddc03379ca50a7ecbc04aea34edc8edc1ce0f84;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 02ed86cd..4994c4e0 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -20,6 +20,7 @@ use File::Copy; use Data::Structure::Util qw(unbless); use Time::HiRes qw(gettimeofday tv_interval); use IO::File; +use DXJSON; use strict; @@ -30,7 +31,7 @@ $dbm = undef; $filename = undef; $lastoperinterval = 60*24*60*60; $lasttime = 0; -$lrusize = 3000; +$lrusize = 10000; $tooold = 86400 * 365; # this marks an old user who hasn't given enough info to be useful $v3 = 0; our $maxconnlist = 3; # remember this many connection time (duration) [start, end] pairs @@ -49,6 +50,7 @@ my $json; email => '0,E-mail Address,parray', priv => '9,Privilege Level', lastin => '0,Last Time in,cldatetime', + lastseen => '0,Last Seen,cldatetime', passwd => '9,Password,yesno', passphrase => '9,Pass Phrase,yesno', addr => '0,Full Address', @@ -93,7 +95,7 @@ my $json; wantcw => '0,Want RBN CW,yesno', wantrtty => '0,Want RBN RTTY,yesno', wantpsk => '0,Want RBN PSK,yesno', - wantbeacon => '0,Want (RBN) Beacon,yesno', + wantbeacon => '0,Want RBN Beacon,yesno', lastoper => '9,Last for/oper,cldatetime', nothere => '0,Not Here Text', registered => '9,Registered?,yesno', @@ -105,6 +107,8 @@ my $json; maxconnect => '1,Max Connections', startt => '0,Start Time,cldatetime', connlist => '1,Connections,parraydifft', + width => '0,Preferred Width', + rbnseeme => '0,RBN See Me', ); #no strict; @@ -132,7 +136,7 @@ sub init { my $mode = shift; - $json = JSON->new->canonical(1); + $json = DXJSON->new->canonical(1); my $fn = "users"; $filename = localdata("$fn.v3j"); unless (-e $filename || $mode == 2) { @@ -179,6 +183,7 @@ sub process sub finish { + $dbm->sync; undef $dbm; untie %u; } @@ -204,6 +209,7 @@ sub new # confess "can't create existing call $call in User\n!" if $u{$call}; my $self = $pkg->alloc($call); + $self->{lastseen} = $main::systime; $self->put; return $self; } @@ -220,7 +226,10 @@ sub get # is it in the LRU cache? my $ref = $lru->get($call); - return $ref if $ref && ref $ref eq 'DXUser'; + if ($ref && ref $ref eq 'DXUser') { + $ref->{lastseen} = $main::systime; + return $ref; + } # search for it unless ($dbm->get($call, $data)) { @@ -240,6 +249,7 @@ sub get } return undef; } + $ref->{lastseen} = $main::systime; $lru->put($call, $ref); return $ref; } @@ -300,25 +310,13 @@ sub put # thaw the user sub decode { - my $s = shift; - my $ref; - eval { $ref = $json->decode($s) }; - if ($ref && !$@) { - return bless $ref, 'DXUser'; - } else { - LogDbg('DXUser', "DXUser::json_decode: on '$s' $@"); - } - return undef; + return $json->decode(shift, __PACKAGE__); } # freeze the user sub encode { - my $ref = shift; - unbless($ref); - my $s = $json->encode($ref); - bless $ref, 'DXUser'; - return $s; + return $json->encode(shift); } @@ -343,7 +341,7 @@ sub close my $self = shift; my $startt = shift; my $ip = shift; - $self->{lastin} = $main::systime; + $self->{lastseen} = $self->{lastin} = $main::systime; # add a record to the connect list my $ref = [$startt || $self->{startt}, $main::systime]; push @$ref, $ip if $ip; @@ -474,10 +472,10 @@ print "There are $count user records and $err errors in $diff mS\n"; my $eval = $val; my $ekey = $key; $eval =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; - $ekey =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; - LogDbg('DXCommand', "Export Error1: $ekey\t$eval"); + $ekey =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; + LogDbg('DXCommand', "Export Error1: invalid call '$key' => '$val'"); eval {$dbm->del($key)}; - dbg(carp("Export Error1: $ekey\t$eval\n$@")) if $@; + dbg(carp("Export Error1: delete $key => '$val' $@")) if $@; ++$err; next; } @@ -488,7 +486,7 @@ print "There are $count user records and $err errors in $diff mS\n"; if ($ref->is_user && !$ref->{priv} && $main::systime > $t + $tooold) { unless ($ref->{lat} && $ref->{long} || $ref->{qth} || $ref->{qra}) { eval {$dbm->del($key)}; - dbg(carp("Export Error2: $key\t$val\n$@")) if $@; + dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@; LogDbg('DXCommand', "$ref->{call} deleted, too old"); $del++; next; @@ -498,9 +496,9 @@ print "There are $count user records and $err errors in $diff mS\n"; print $fh "$key\t" . encode($ref) . "\n"; ++$count; } else { - LogDbg('DXCommand', "Export Error3: $key\t" . carp($val) ."\n$@"); + LogDbg('DXCommand', "Export Error3: '$key'\t" . carp($val) ."\n$@"); eval {$dbm->del($key)}; - dbg(carp("Export Error3: $key\t$val\n$@")) if $@; + dbg(carp("Export Error3: delete '$key' => '$val' $@")) if $@; ++$err; } } @@ -663,7 +661,7 @@ sub wanttalk sub wantgrid { - return _want('grid', @_); + return _wantnot('grid', @_); } sub wantemail @@ -698,12 +696,12 @@ sub wantusstate sub wantdxcq { - return _want('dxcq', @_); + return _wantnot('dxcq', @_); } sub wantdxitu { - return _want('dxitu', @_); + return _wantnot('dxitu', @_); } sub wantgtk