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