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