a1fecbad1acba3eb5a75b9274b5f2a103c7fa84e
[spider.git] / perl / DXUser.pm
1 #
2 # DX cluster user routines
3 #
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
5 #
6 #
7 #
8
9 package DXUser;
10
11 use DXLog;
12 use DB_File;
13 use Data::Dumper;
14 use Fcntl;
15 use IO::File;
16 use DXDebug;
17 use DXUtil;
18 use LRU;
19 use File::Copy;
20 use Data::Structure::Util qw(unbless);
21 use Time::HiRes qw(gettimeofday tv_interval);
22 use IO::File;
23 use DXJSON;
24
25 use strict;
26
27 use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize $tooold $veryold $v3);
28
29 %u = ();
30 $dbm = undef;
31 $filename = undef;
32 $lastoperinterval = 60*24*60*60;
33 $lasttime = 0;
34 $lrusize = 5000;
35 $tooold = 86400 * 365 * 2;              # this marks an old user who hasn't given enough info to be useful
36 $veryold = $tooold * 6;         # Ancient default 12 years
37 $v3 = 0;
38 our $maxconnlist = 3;                   # remember this many connection time (duration) [start, end] pairs
39
40 my $json;
41
42 # hash of valid elements and a simple prompt
43 %valid = (
44                   'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
45                   K => '9,Seen on PC92 K,yesno',
46                   addr => '0,Full Address',
47                   addr => '0,Full Address',
48                   alias => '0,Real Callsign',
49                   alias => '0,Real Callsign',
50                   annok => '9,Accept Announces?,yesno', # accept his announces?
51                   bbs => '0,Home BBS',
52                   believe => '1,Believable nodes,parray',
53                   believe => '1,Believable nodes,parray',
54                   buddies => '0,Buddies,parray',
55                   build => '1,Build',
56                   build => '1,Build',
57                   call => '0,Callsign',
58                   call => '0,Callsign',
59                   connlist => '1,Connections,parraydifft',
60                   dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
61                   email => '0,E-mail Address,parray',
62                   email => '0,E-mail Address,parray',
63                   group => '0,Group,parray',    # used to create a group of users/nodes for some purpose or other
64                   hmsgno => '0,Highest Msgno',
65                   homenode => '0,Home Node',
66                   isolate => '9,Isolate network,yesno',
67                   lang => '0,Language',
68                   lastin => '0,Last Time in,cldatetime',
69                   lastin => '0,Last Time in,cldatetime',
70                   lastoper => '9,Last for/oper,cldatetime',
71                   lastoper => '9,Last for/oper,cldatetime',
72                   lastping => '1,Last Ping at,ptimelist',
73                   lastping => '1,Last Ping at,ptimelist',
74                   lastseen => '0,Last Seen,cldatetime',
75                   lat => '0,Latitude,slat',
76                   lockout => '9,Locked out?,yesno',     # won't let them in at all
77                   long => '0,Longitude,slong',
78                   maxconnect => '1,Max Connections',
79                   name => '0,Name',
80                   node => '0,Last Node',
81                   nopings => '9,Ping Obs Count',
82                   nothere => '0,Not Here Text',
83                   pagelth => '0,Current Pagelth',
84                   passphrase => '9,Pass Phrase,yesno',
85                   passwd => '9,Password,yesno',
86                   pingint => '9,Node Ping interval',
87                   priv => '9,Privilege Level',
88                   prompt => '0,Required Prompt',
89                   qra => '0,Locator',
90                   qth => '0,Home QTH',
91                   rbnseeme => '0,RBN See Me',
92                   registered => '9,Registered?,yesno',
93                   startt => '0,Start Time,cldatetime',
94                   version => '1,Version',
95                   wantann => '0,Req Announce,yesno',
96                   wantann_talk => '0,Talklike Anns,yesno',
97                   wantbeacon => '0,Want RBN Beacon,yesno',
98                   wantbeep => '0,Req Beep,yesno',
99                   wantcw => '0,Want RBN CW,yesno',
100                   wantdx => '0,Req DX Spots,yesno',
101                   wantdxcq => '0,Show CQ Zone,yesno',
102                   wantdxitu => '0,Show ITU Zone,yesno',
103                   wantecho => '0,Req Echo,yesno',
104                   wantemail => '0,Req Msgs as Email,yesno',
105                   wantft => '0,Want RBN FT4/8,yesno',
106                   wantgtk => '0,Want GTK interface,yesno',
107                   wantlogininfo => '0,Login Info Req,yesno',
108                   wantpc16 => '9,Want Users from node,yesno',
109                   wantpc9x => '0,Want PC9X interface,yesno',
110                   wantpsk => '0,Want RBN PSK,yesno',
111                   wantrbn => '0,Want RBN spots,yesno',
112                   wantroutepc19 => '9,Route PC19,yesno',
113                   wantrtty => '0,Want RBN RTTY,yesno',
114                   wantsendpc16 => '9,Send PC16,yesno',
115                   wanttalk => '0,Req Talk,yesno',
116                   wantusstate => '0,Show US State,yesno',
117                   wantwcy => '0,Req WCY,yesno',
118                   wantwwv => '0,Req WWV,yesno',
119                   wantwx => '0,Req WX,yesno',
120                   width => '0,Preferred Width',
121                   xpert => '0,Expert Status,yesno',
122           wantgrid => '0,Show DX Grid,yesno',
123                  );
124
125 #no strict;
126 sub AUTOLOAD
127 {
128         no strict;
129         my $name = $AUTOLOAD;
130   
131         return if $name =~ /::DESTROY$/;
132         $name =~ s/^.*:://o;
133   
134         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
135         # this clever line of code creates a subroutine which takes over from autoload
136         # from OO Perl - Conway
137         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
138        goto &$AUTOLOAD;
139 }
140
141 #use strict;
142
143 #
144 # initialise the system
145 #
146 sub init
147 {
148         my $mode = shift;
149   
150         $json = DXJSON->new->canonical(1);
151         my $fn = "users";
152         $filename = localdata("$fn.v3j");
153         unless (-e $filename || $mode == 2 ) {
154                 if (-e localdata("$fn.v3") || -e localdata("$fn.v2")) {
155                         LogDbg('DXUser', "New User File version $filename does not exist, running conversion from users.v3 or v2, please wait");
156                         system('/spider/perl/convert-users-v3-to-v3j.pl');
157                         init(1);
158                         export();
159                         return;
160                 }
161         }
162         if (-e $filename || $mode) {
163                 $lru = LRU->newbase("DXUser", $lrusize);
164                 if ($mode) {
165                         $dbm = tie (%u, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
166                 } else {
167                         $dbm = tie (%u, 'DB_File', $filename, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
168                 }
169         }
170         die "Cannot open $filename ($!)\n" unless $dbm || $mode == 2;
171         return;
172 }
173
174 # delete files with extreme prejudice
175 sub del_file
176 {
177         # with extreme prejudice
178         unlink "$main::data/users.v3j";
179         unlink "$main::local_data/users.v3j";
180 }
181
182 #
183 # periodic processing
184 #
185 sub process
186 {
187         if ($main::systime > $lasttime + 15) {
188                 $dbm->sync if $dbm;
189                 $lasttime = $main::systime;
190         }
191 }
192
193 #
194 # close the system
195 #
196
197 sub finish
198 {
199         $dbm->sync;
200         undef $dbm;
201         untie %u;
202 }
203
204 #
205 # new - create a new user
206 #
207
208 sub alloc
209 {
210         my $pkg = shift;
211         my $call = uc shift;
212         my $self = bless {call => $call, 'sort'=>'U'}, $pkg;
213         return $self;
214 }
215
216 sub new
217 {
218         my $pkg = shift;
219         my $call = shift;
220         #  $call =~ s/-\d+$//o;
221   
222 #       confess "can't create existing call $call in User\n!" if $u{$call};
223
224         my $self = $pkg->alloc($call);
225         $self->put;
226         return $self;
227 }
228
229 #
230 # get - get an existing user - this seems to return a different reference everytime it is
231 #       called - see below
232 #
233
234 sub get
235 {
236         my $call = uc shift;
237         my $data;
238         
239         # is it in the LRU cache?
240         my $ref = $lru->get($call);
241         if ($ref && ref $ref eq 'DXUser') {
242                 return $ref;
243         }
244         
245         # search for it
246         unless ($dbm->get($call, $data)) {
247                 eval { $ref = decode($data); };
248                 if ($ref) {
249                         if (!UNIVERSAL::isa($ref, 'DXUser')) {
250                                 dbg("DXUser::get: got strange answer from decode of $call". ref $ref. " ignoring");
251                                 return undef;
252                         }
253                         # we have a reference and it *is* a DXUser
254                 } else {
255                         if ($@) {
256                                 LogDbg('err', "DXUser::get decode error on $call '$@'");
257                         } else {
258                                 dbg("DXUser::get: no reference returned from decode of $call $!");
259                         }
260                         return undef;
261                 }
262                 $lru->put($call, $ref);
263                 return $ref;
264         }
265         return undef;
266 }
267
268 #
269 # get an existing either from the channel (if there is one) or from the database
270 #
271 # It is important to note that if you have done a get (for the channel say) and you
272 # want access or modify that you must use this call (and you must NOT use get's all
273 # over the place willy nilly!)
274 #
275
276 sub get_current
277 {
278         my $call = uc shift;
279   
280         my $dxchan = DXChannel::get($call);
281         if ($dxchan) {
282                 my $ref = $dxchan->user;
283                 return $ref if $ref && UNIVERSAL::isa($ref, 'DXUser');
284
285                 dbg("DXUser::get_current: got invalid user ref for $call from dxchan $dxchan->{call} ". ref $ref. " ignoring");
286         }
287         return get($call);
288 }
289
290 #
291 # get all callsigns in the database 
292 #
293
294 sub get_all_calls
295 {
296         return (sort keys %u);
297 }
298
299 #
300 # put - put a user
301 #
302
303 sub put
304 {
305         my $self = shift;
306         confess "Trying to put nothing!" unless $self && ref $self;
307         my $call = $self->{call};
308
309         $dbm->del($call);
310         delete $self->{annok};
311         delete $self->{dxok};
312         $self->{lastseen} = $main::systime;
313         $lru->put($call, $self);
314         my $ref = $self->encode;
315         $dbm->put($call, $ref);
316 }
317
318
319 # thaw the user
320 sub decode
321 {
322         return $json->decode(shift, __PACKAGE__);
323 }
324
325 # freeze the user
326 sub encode
327 {
328         return $json->encode(shift);
329 }
330
331
332 #
333 # del - delete a user
334 #
335
336 sub del
337 {
338         my $self = shift;
339         my $call = $self->{call};
340         $lru->remove($call);
341         $dbm->del($call);
342 }
343
344 #
345 # close - close down a user
346 #
347
348 sub close
349 {
350         my $self = shift;
351         my $startt = shift;
352         my $ip = shift;
353         # add a record to the connect list
354         $self->{lastin} = $main::systime;
355         my $ref = [$startt || $self->{startt}, $main::systime];
356         push @$ref, $ip if $ip;
357         push @{$self->{connlist}}, $ref;
358         shift @{$self->{connlist}} if @{$self->{connlist}} > $maxconnlist;
359         $self->put();
360 }
361
362 #
363 # sync the database
364 #
365
366 sub sync
367 {
368         $dbm->sync;
369 }
370
371 #
372 # return a list of valid elements 
373
374
375 sub fields
376 {
377         return keys(%valid);
378 }
379
380
381 #
382 # export the database to an ascii file
383 #
384
385 sub export
386 {
387         my $name = shift || 'user_json';
388         my $basic_info_only = shift;
389
390         my $fn = $name ne 'user_json' ? $name : "$main::local_data/$name";                       # force use of local
391         
392         # save old ones
393         copy $fn, "$fn.keep" unless -e "$fn.keep";
394         copy "$fn.ooooo", "$fn.backstop" unless -e "$fn,backstop";
395
396         move "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
397         move "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
398         move "$fn.oo", "$fn.ooo" if -e "$fn.oo";
399         move "$fn.o", "$fn.oo" if -e "$fn.o";
400         move "$fn", "$fn.o" if -e "$fn";
401
402         
403         my $ta = [gettimeofday];
404         my $count = 0;
405         my $err = 0;
406         my $del = 0;
407         my $spurious = 0;
408         my $unlocked = 0;
409         my $old =  0;
410         my $ancient =  0;
411         my $nodes = 0;
412         my $renamed = 0;
413                 
414         my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
415         if ($fh) {
416                 my $key = 0;
417                 my $val = undef;
418                 my $action;
419                 my $t = scalar localtime;
420                 print $fh q{#!/usr/bin/perl
421 #
422 # The exported userfile for a DXSpider System
423 #
424 # Input file: $filename
425 #       Time: $t
426 #
427                         
428 package main;
429                         
430 # search local then perl directories
431 BEGIN {
432         umask 002;
433                                 
434         # root of directory tree for this system
435         $root = "/spider"; 
436         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
437         
438         unshift @INC, "$root/perl";     # this IS the right way round!
439         unshift @INC, "$root/local";
440         
441         # try to detect a lockfile (this isn't atomic but 
442         # should do for now
443         $lockfn = "$root/local_data/cluster.lck";       # lock file name
444         if (-e $lockfn) {
445                 open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
446                 my $pid = <CLLOCK>;
447                 chomp $pid;
448                 die "Lockfile ($lockfn) and process $pid exists - cluster must be stopped first\n" if kill 0, $pid;
449                 close CLLOCK;
450         }
451 }
452
453 use SysVar;
454 use DXUtil;
455 use DXUser;
456 use JSON;
457 use Time::HiRes qw(gettimeofday tv_interval);
458 package DXUser;
459
460 our $json = JSON->new->canonical(1);
461
462 my $ta = [gettimeofday];
463 our $filename = "$main::local_data/users.v3j";
464 my $exists = -e $filename ? "OVERWRITING" : "CREATING"; 
465 print "perl user_json $exists $filename\n";
466
467 del_file();
468 init(2);
469 %u = ();
470 my $count = 0;
471 my $err = 0;
472 while (<DATA>) {
473         chomp;
474         my @f = split /\t/;
475         my $ref = decode($f[1]);
476         if ($ref) {
477                 $ref->put();
478                 $count++;
479         } else {
480                 print "# Error: $f[0]\t$f[1]\n";
481                 $err++
482         }
483 }
484 DXUser::sync(); DXUser::finish();
485 my $diff = _diffms($ta);
486 print "There are $count user records and $err errors in $diff mS\n";
487 };
488                 print $fh "__DATA__\n";
489
490         for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) {
491                         if (!is_callsign($key) || $key =~ /^0/) {
492                                 my $eval = $val;
493                                 my $ekey = $key;
494                                 $eval =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; 
495                                 $ekey =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
496                                 LogDbg('DXCommand', "Export Error1: invalid call '$key' => '$val'");
497                                 eval {$dbm->del($key)};
498                             dbg(carp("Export Error1: delete $key => '$val' $@")) if $@;
499                                 ++$err;
500                                 next;
501                         }
502                         my $ref;
503                         eval {$ref = decode($val); };
504                         if ($ref) {
505                                 my $t = $ref->{lastseen} if exists $ref->{lastseen};
506                                 $t ||= $ref->{lastin} if exists $ref->{lastin};
507                                 $t ||= $ref->{lastoper} if exists $ref->{lastoper};
508                                 $t //= 0;
509                                 
510                                 if ($ref->is_user) {
511                                         if (!$ref->{priv} && $main::systime > $t + $tooold) {
512                                                 unless (($ref->{lat} && $ref->{long}) || $ref->{qth} || $ref->{name} || $ref->{qra}) {
513                                                         LogDbg('DXCommand', sprintf("$ref->{call} deleted, empty and too Old at %s", difft($t, ' ')));
514                                                         ++$del;
515                                                         ++$old;
516                                                         eval {$dbm->del($key)};
517                                                         dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
518                                                         next;
519                                                 }
520                                         }
521                                         if ($main::systime > $t + $veryold) {
522                                                 LogDbg('DXCommand', sprintf("$ref->{call} deleted, POSITIVELY ANCIENT at %s", difft($t, ' ')));
523                                                 ++$del;
524                                                 ++$ancient;
525                                                 eval {$dbm->del($key)};
526                                                 dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
527                                                 next;
528                                         }
529                                         if (exists $ref->{lockout} && $ref->{lockout} == 1 && exists $ref->{priv} && $ref->{priv} == 1) {
530                                                 LogDbg('DXCommand', "$ref->{call} depriv'd and unlocked");
531                                                 $ref->{lockout} = $ref->{priv} = 0;
532                                                 $ref->put;
533                                                 ++$unlocked;
534                                         }
535                                         if ($ref->is_node && $main::systime > $t + $veryold) {
536                                                 LogDbg('DXCommand', sprintf("NODE $ref->{call} deleted (%s) old", difft($t, ' ')));
537                                                 ++$del;
538                                                 ++$nodes;
539                                                 eval {$dbm->del($key)};
540                                                 dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
541                                                 next;
542                                         }
543                                         
544                                         my $normcall = normalise_call($key);
545                                         if ($normcall ne $key) {
546                                                 # if the normalised call does not exist, create it from the duff call.
547                                                 my $nref = DXUser::get_current($normcall);
548                                                 unless ($nref) {
549                                                         $ref->{call} = $normcall;
550                                                         $ref->put;
551                                                         LogDbg('DXCommand', "DXProt: spurious call $key normalises to $normcall renaming $key -> $normcall");
552                                                         ++$renamed;
553                                                 } 
554                                                 LogDbg('DXCommand', "DXProt: spurious call $key (should be $normcall), removing");
555                                                 eval {$dbm->del($key)};
556                                                 dbg(carp("Export Error1: delete $key => '$val' $@")) if $@;
557                                                 ++$spurious;
558                                                 ++$del;
559                                                 next;
560                                         }
561                                 }
562                         } else {
563                                 LogDbg('DXCommand', "Export Error3: '$key'\t" . carp($val) ."\n$@");
564                                 eval {$dbm->del($key)};
565                                 dbg(carp("Export Error3: delete '$key' => '$val' $@")) if $@;
566                                 ++$err;
567                                 next;
568                         }
569                         
570                         # only store users that are reasonably active or have useful information
571                         print $fh "$key\t" . encode($ref) . "\n";
572                         ++$count;
573                 }
574         } 
575         $fh->close;
576
577         my $diff = _diffms($ta);
578         my $s = qq{Exported users to $fn - $count Users,  $del Deleted ($old empty \& too old, $ancient ancient, $nodes nodes, $spurious spurious), $renamed renamed, $unlocked Unlocked, $err Errors in $diff mS ('sh/log Export' for details)};
579         LogDbg('command', $s);
580         return $s;
581 }
582
583 #
584 # group handling
585 #
586
587 # add one or more groups
588 sub add_group
589 {
590         my $self = shift;
591         my $ref = $self->{group} || [ 'local' ];
592         $self->{group} = $ref if !$self->{group};
593         push @$ref, @_ if @_;
594 }
595
596 # remove one or more groups
597 sub del_group
598 {
599         my $self = shift;
600         my $ref = $self->{group} || [ 'local' ];
601         my @in = @_;
602         
603         $self->{group} = $ref if !$self->{group};
604         
605         @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
606 }
607
608 # does this thing contain all the groups listed?
609 sub union
610 {
611         my $self = shift;
612         my $ref = $self->{group};
613         my $n;
614         
615         return 0 if !$ref || @_ == 0;
616         return 1 if @$ref == 0 && @_ == 0;
617         for ($n = 0; $n < @_; ) {
618                 for (@$ref) {
619                         my $a = $_;
620                         $n++ if grep $_ eq $a, @_; 
621                 }
622         }
623         return $n >= @_;
624 }
625
626 # simplified group test just for one group
627 sub in_group
628 {
629         my $self = shift;
630         my $s = shift;
631         my $ref = $self->{group};
632         
633         return 0 if !$ref;
634         return grep $_ eq $s, $ref;
635 }
636
637 # set up a default group (only happens for them's that connect direct)
638 sub new_group
639 {
640         my $self = shift;
641         $self->{group} = [ 'local' ];
642 }
643
644 # set up empty buddies (only happens for them's that connect direct)
645 sub new_buddies
646 {
647         my $self = shift;
648         $self->{buddies} = [  ];
649 }
650
651 #
652 # return a prompt for a field
653 #
654
655 sub field_prompt
656
657         my ($self, $ele) = @_;
658         return $valid{$ele};
659 }
660
661 # some variable accessors
662 sub sort
663 {
664         my $self = shift;
665         @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
666 }
667
668 # some accessors
669
670 # want is default = 1
671 sub _want
672 {
673         my $n = shift;
674         my $self = shift;
675         my $val = shift;
676         my $s = "want$n";
677         $self->{$s} = $val if defined $val;
678         return exists $self->{$s} ? $self->{$s} : 1;
679 }
680
681 # wantnot is default = 0
682 sub _wantnot
683 {
684         my $n = shift;
685         my $self = shift;
686         my $val = shift;
687         my $s = "want$n";
688         $self->{$s} = $val if defined $val;
689         return exists $self->{$s} ? $self->{$s} : 0;
690 }
691
692 sub wantbeep
693 {
694         return _want('beep', @_);
695 }
696
697 sub wantann
698 {
699         return _want('ann', @_);
700 }
701
702 sub wantwwv
703 {
704         return _want('wwv', @_);
705 }
706
707 sub wantwcy
708 {
709         return _want('wcy', @_);
710 }
711
712 sub wantecho
713 {
714         return _want('echo', @_);
715 }
716
717 sub wantwx
718 {
719         return _want('wx', @_);
720 }
721
722 sub wantdx
723 {
724         return _want('dx', @_);
725 }
726
727 sub wanttalk
728 {
729         return _want('talk', @_);
730 }
731
732 sub wantgrid
733 {
734         return _wantnot('grid', @_);
735 }
736
737 sub wantemail
738 {
739         return _want('email', @_);
740 }
741
742 sub wantann_talk
743 {
744         return _want('ann_talk', @_);
745 }
746
747 sub wantpc16
748 {
749         return _want('pc16', @_);
750 }
751
752 sub wantsendpc16
753 {
754         return _want('sendpc16', @_);
755 }
756
757 sub wantroutepc16
758 {
759         return _want('routepc16', @_);
760 }
761
762 sub wantusstate
763 {
764         return _want('usstate', @_);
765 }
766
767 sub wantdxcq
768 {
769         return _wantnot('dxcq', @_);
770 }
771
772 sub wantdxitu
773 {
774         return _wantnot('dxitu', @_);
775 }
776
777 sub wantgtk
778 {
779         return _want('gtk', @_);
780 }
781
782 sub wantpc9x
783 {
784         return _want('pc9x', @_);
785 }
786
787 sub wantlogininfo
788 {
789         my $self = shift;
790         my $val = shift;
791         $self->{wantlogininfo} = $val if defined $val;
792         return $self->{wantlogininfo};
793 }
794
795 sub is_node
796 {
797         my $self = shift;
798         return $self->{sort} =~ /^[ACRSX]$/;
799 }
800
801 sub is_local_node
802 {
803         my $self = shift;
804         return grep $_ eq 'local_node', @{$self->{group}};
805 }
806
807 sub is_user
808 {
809         my $self = shift;
810         return $self->{sort} =~ /^[UW]$/;
811 }
812
813 sub is_web
814 {
815         my $self = shift;
816         return $self->{sort} eq 'W';
817 }
818
819 sub is_bbs
820 {
821         my $self = shift;
822         return $self->{sort} eq 'B';
823 }
824
825 sub is_spider
826 {
827         my $self = shift;
828         return $self->{sort} eq 'S';
829 }
830
831 sub is_clx
832 {
833         my $self = shift;
834         return $self->{sort} eq 'C';
835 }
836
837 sub is_dxnet
838 {
839         my $self = shift;
840         return $self->{sort} eq 'X';
841 }
842
843 sub is_arcluster
844 {
845         my $self = shift;
846         return $self->{sort} eq 'R';
847 }
848
849 sub is_ak1a
850 {
851         my $self = shift;
852         return $self->{sort} eq 'A';
853 }
854
855 sub is_rbn
856 {
857         my $self = shift;
858         return $self->{sort} eq 'N'
859 }
860
861 sub unset_passwd
862 {
863         my $self = shift;
864         delete $self->{passwd};
865 }
866
867 sub unset_passphrase
868 {
869         my $self = shift;
870         delete $self->{passphrase};
871 }
872
873 sub set_believe
874 {
875         my $self = shift;
876         my $call = uc shift;
877         $self->{believe} ||= [];
878         push @{$self->{believe}}, $call unless grep $_ eq $call, @{$self->{believe}};
879 }
880
881 sub unset_believe
882 {
883         my $self = shift;
884         my $call = uc shift;
885         if (exists $self->{believe}) {
886                 $self->{believe} = [grep {$_ ne $call} @{$self->{believe}}];
887                 delete $self->{believe} unless @{$self->{believe}};
888         }
889 }
890
891 sub believe
892 {
893         my $self = shift;
894         return exists $self->{believe} ? @{$self->{believe}} : ();
895 }
896
897 sub lastping
898 {
899         my $self = shift;
900         my $call = shift;
901         $self->{lastping} ||= {};
902         $self->{lastping} = {} unless ref $self->{lastping};
903         my $b = $self->{lastping};
904         $b->{$call} = shift if @_;
905         return $b->{$call};     
906 }
907
908 #sub registered
909 #{
910 #       my $self = shift;
911 #       my $val;
912 #       if (defined $_[0]) {
913 #               $val = unpad($_[0]);
914 #               $self->{registered} = $val;
915 #       }
916 #       if (exists $self->{registered}) {
917 #               $val = $self->{registered} // 0;
918 #       }
919 #       return $val // 0 ;                                      # to stop undef warnings
920 #}
921
922 1;
923 __END__
924
925
926
927
928