Improve M$ Windows compatibility
[spider.git] / perl / DXChannel.pm
1 #
2 # module to manage channel lists & data
3 #
4 # This is the base class for all channel operations, which is everything to do 
5 # with input and output really.
6 #
7 # The instance variable in the outside world will be generally be called $dxchan
8 #
9 # This class is 'inherited' (if that is the goobledegook for what I am doing)
10 # by various other modules. The point to understand is that the 'instance variable'
11 # is in fact what normal people would call the state vector and all useful info
12 # about a connection goes in there.
13 #
14 # Another point to note is that a vector may contain a list of other vectors. 
15 # I have simply added another variable to the vector for 'simplicity' (or laziness
16 # as it is more commonly called)
17 #
18 # PLEASE NOTE - I am a C programmer using this as a method of learning perl
19 # firstly and OO about ninthly (if you don't like the design and you can't 
20 # improve it with better OO and thus make it smaller and more efficient, then tough). 
21 #
22 # Copyright (c) 1998-2016 - Dirk Koopman G1TLH
23 #
24 #
25 #
26 package DXChannel;
27
28 use Msg;
29 use DXM;
30 use DXUtil;
31 use DXVars;
32 use DXDebug;
33 use Filter;
34 use Prefix;
35 use Route;
36
37 use strict;
38 use vars qw(%channels %valid @ISA $count $maxerrors);
39
40 %channels = ();
41 $count = 0;
42
43 %valid = (
44                   'sort' => '5,Type of Channel',
45                   ann => '0,Want Announce,yesno',
46                   ann_talk => '0,Suppress Talk Anns,yesno',
47                   annfilter => '5,Ann Filt-out',
48                   badcount => '1,Bad Word Count',
49                   badip => '9,BAD IP address',
50                   beep => '0,Want Beeps,yesno',
51                   build => '1,Node Build',
52                   call => '0,Callsign',
53                   cluster => '5,Cluster data',
54                   conf => '0,In Conference?,yesno',
55                   conn => '9,Msg Conn ref',
56                   consort => '5,Connection Type',
57                   cq => '0,CQ Zone',
58                   delayed => '5,Delayed messages,parray',
59                   disconnecting => '9,Disconnecting,yesno',
60                   do_pc9x => '9,Handles PC9x,yesno',
61                   dx => '0,DX Spots,yesno',
62                   dxcc => '0,Country Code',
63                   edit => '7,Edit Function',
64                   enhanced => '5,Enhanced Client,yesno',
65                   errors => '9,Errors',
66                   func => '5,Function',
67                   group => '0,Access Group,parray',     # used to create a group of users/nodes for some purpose or other.
68                   gtk => '5,Using GTK,yesno',
69                   handle_xml => '9,Handles XML,yesno',
70                   here => '0,Here?,yesno',
71                   hostname => '0,Hostname',
72                   inannfilter => '5,Ann Filt-inp',
73                   inpc92filter => '5,PC92 Route Filt-inp',
74                   inqueue => '9,Input Queue,parray',
75                   inrbnfilter => '5,RBN Filt-inp',
76                   inroutefilter => '5,Route Filt-inp',
77                   inscript => '9,In a script,yesno',
78                   inspotsfilter => '5,Spot Filt-inp',
79                   inwcyfilter => '5,WCY Filt-inp',
80                   inwwvfilter => '5,WWV Filt-inp',
81                   isbasic => '9,Internal Connection', 
82                   isolate => '5,Isolate network,yesno',
83                   isslugged => '9,Still Slugged,yesno',
84                   itu => '0,ITU Zone',
85                   K => '9,Seen on PC92 K,yesno',
86                   lang => '0,Language',
87                   lastmsgpoll => '0,Last Msg Poll,atime',
88                   lastping => '5,Ping last sent,atime',
89                   lastread => '5,Last Msg Read',
90                   list => '9,Dep Chan List',
91                   loc => '9,Local Vars', # used by func to store local variables in
92                   logininfo => '9,Login info req,yesno',
93                   metric => '1,Route metric',
94                   name => '0,User Name',
95                   newroute => '1,New Style Routing,yesno',
96                   next_pc92_keepalive => '9,Next PC92 KeepAlive,atime',
97                   next_pc92_update => '9,Next PC92 Update,atime',
98                   nopings => '5,Ping Obs Count',
99                   oldstate => '5,Last State',
100                   outbound => '5,outbound?,yesno',
101                   pagedata => '9,Page Data Store',
102                   pagelth => '0,Page Length',
103                   passwd => '9,Passwd List,yesno',
104                   pc50_t => '5,Last PC50 Time,atime',
105                   pc92filter => '5,PC92 Route Filt-out',
106                   pingave => '0,Ping ave time',
107                   pingint => '5,Ping Interval ',
108                   pingtime => '5,Ping totaltime,parray',
109                   priv => '9,Privilege',
110                   prompt => '0,Required Prompt',
111                   rbnfilter => '5,RBN Filt-out',
112                   rbnseeme => '0,RBN See Me,yesno',
113                   redirect => '0,Redirect messages to',
114                   registered => '9,Registered?,yesno',
115                   remotecmd => '9,doing rcmd,yesno',
116                   route => '9,Route Data',
117                   routefilter => '5,Route Filt-out',
118                   senddbg => '8,Sending Debug,yesno',
119                   sluggedpcs => '9,Slugged PCxx Queue,parray',
120                   spotsfilter => '5,Spot Filt-out',
121                   startt => '0,Start Time,atime',
122                   state => '0,Current State',
123                   t => '9,Time,atime',
124                   talk => '0,Want Talk,yesno',
125                   talklist => '0,Talk List,parray',
126                   user => '9,DXUser ref',
127                   ve7cc => '0,VE7CC program special,yesno',
128                   verified => '9,Verified?,yesno',
129                   version => '1,Node Version',
130                   wcy => '0,Want WCY,yesno',
131                   wcyfilter => '5,WCY Filt-out',
132                   width => '0,Column Width',
133                   wwv => '0,Want WWV,yesno',
134                   wwvfilter => '5,WWV Filt-out',
135                   wx => '0,Want WX,yesno',                
136                  );
137
138 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
139
140 # object destruction
141 sub DESTROY
142 {
143         my $self = shift;
144         for (keys %$self) {
145                 if (ref($self->{$_})) {
146                         delete $self->{$_};
147                 }
148         }
149         dbg("DXChannel $self->{call} destroyed ($count)") if isdbg('chan');
150         $count--;
151 }
152
153 # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)]
154 sub alloc
155 {
156         my ($pkg, $call, $conn, $user) = @_;
157         my $self = {};
158   
159         die "trying to create a duplicate channel for $call" if $channels{$call};
160         $self->{call} = $call;
161         $self->{priv} = 0;
162         $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list
163         if (defined $user) {
164                 $self->{user} = $user;
165                 $self->{lang} = $user->lang;
166                 $user->new_group unless $user->group;
167                 $user->new_buddies unless $user->buddies;
168                 $self->{group} = $user->group;
169                 $self->{sort} = $user->sort;
170                 $self->{width} = $user->width;
171         }
172         $self->{startt} = $self->{t} = $main::systime;
173         $self->{state} = 0;
174         $self->{oldstate} = 0;
175         $self->{lang} = $main::lang if !$self->{lang};
176         $self->{func} = "";
177         $self->{width} ||=  80;
178         $self->{_nospawn} = 0;
179
180         # add in all the dxcc, itu, zone info
181         my @dxcc = Prefix::extract($call);
182         if (@dxcc > 0) {
183                 $self->{dxcc} = $dxcc[1]->dxcc;
184                 $self->{itu} = $dxcc[1]->itu;
185                 $self->{cq} = $dxcc[1]->cq;
186         }
187         $self->{inqueue} = [];
188
189         if ($conn) {
190                 $self->{hostname} = $self->{conn}->peerhost;
191                 $self->{sockhost} = $self->{conn}->sockhost;
192         }
193
194         $count++;
195         dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
196         bless $self, $pkg; 
197         return $channels{$call} = $self;
198 }
199
200 # count errors and disconnect if too many
201 # this has to be here because it can come from rcmd (DXProt) as
202 # well as DXCommandmode.
203 sub _error_out
204 {
205         my $self = shift;
206         my $e = shift;
207         if (++$self->{errors} > $maxerrors) {
208                 $self->send($self->msg('e26'));
209                 $self->disconnect;
210                 return ();
211         } else {
212                 return ($self->msg($e));
213         }
214 }
215
216 # rebless this channel as something else
217 sub rebless
218 {
219         my $self = shift;
220         my $class = shift;
221         return $channels{$self->{call}} = bless $self, $class;
222 }
223
224 sub rec 
225 {
226         my ($self, $msg) = @_;
227         
228         # queue the message and the channel object for later processing
229         if (defined $msg) {
230                 push @{$self->{inqueue}}, $msg;
231         }
232         $self->process_one;
233 }
234
235 # obtain a channel object by callsign [$obj = DXChannel::get($call)]
236 sub get
237 {
238         my $call = shift;
239         return $channels{$call};
240 }
241
242 # obtain all the channel objects
243 sub get_all
244 {
245         return values(%channels);
246 }
247
248 #
249 # gimme all the ak1a nodes
250 #
251 sub get_all_nodes
252 {
253         my $ref;
254         my @out;
255         foreach $ref (values %channels) {
256                 push @out, $ref if $ref->is_node;
257         }
258         return @out;
259 }
260
261 # return a list of node calls
262 sub get_all_node_calls
263 {
264         my $ref;
265         my @out;
266         foreach $ref (values %channels) {
267                 push @out, $ref->{call} if $ref->is_node;
268         }
269         return @out;
270 }
271
272 # return a list of all users
273 sub get_all_users
274 {
275         my $ref;
276         my @out;
277         foreach $ref (values %channels) {
278                 push @out, $ref if $ref->is_user;
279         }
280         return @out;
281 }
282
283 # return a list of all user callsigns
284 sub get_all_user_calls
285 {
286         my $ref;
287         my @out;
288         foreach $ref (values %channels) {
289                 push @out, $ref->{call} if $ref->is_user;
290         }
291         return @out;
292 }
293
294 # obtain a channel object by searching for its connection reference
295 sub get_by_cnum
296 {
297         my ($pkg, $conn) = @_;
298         my $self;
299   
300         foreach $self (values(%channels)) {
301                 return $self if ($self->{conn} == $conn);
302         }
303         return undef;
304 }
305
306 # get rid of a channel object [$obj->del()]
307 sub del
308 {
309         my $self = shift;
310
311         $self->{group} = undef;         # belt and braces
312         delete $channels{$self->{call}};
313 }
314
315 # is it a bbs
316 sub is_bbs
317 {
318         return $_[0]->{sort} eq 'B';
319 }
320
321 sub is_node
322 {
323         return $_[0]->{sort} =~ /^[ACRSX]$/;
324 }
325 # is it an ak1a node ?
326 sub is_ak1a
327 {
328         return $_[0]->{sort} eq 'A';
329 }
330
331 # is it a user?
332 sub is_user
333 {
334         return $_[0]->{sort} =~ /^[UW]$/;
335 }
336
337 # is it a clx node
338 sub is_clx
339 {
340         return $_[0]->{sort} eq 'C';
341 }
342
343 # it is a Web connected user
344 sub is_web
345 {
346         return $_[0]->{sort} eq 'W';
347 }
348
349 # is it a spider node
350 sub is_spider
351 {
352         return $_[0]->{sort} eq 'S';
353 }
354
355 # is it a DXNet node
356 sub is_dxnet
357 {
358         return $_[0]->{sort} eq 'X';
359 }
360
361 # is it a ar-cluster node
362 sub is_arcluster
363 {
364         return $_[0]->{sort} eq 'R';
365 }
366
367 sub is_rbn
368 {
369         return $_[0]->{sort} eq 'N';
370 }
371
372 sub is_dslink
373 {
374         return $_[0]->{sort} eq 'L';
375 }
376
377 # for perl 5.004's benefit
378 sub sort
379 {
380         my $self = shift;
381         return @_ ? $self->{sort} = shift : $self->{sort} ;
382 }
383
384 # find out whether we are prepared to believe this callsign on this interface
385 sub is_believed
386 {
387         my $self = shift;
388         my $call = shift;
389         
390         return grep $call eq $_, $self->user->believe;
391 }
392
393 # handle out going messages, immediately without waiting for the select to drop
394 # this could, in theory, block
395 sub send_now
396 {
397         my $self = shift;
398         my $conn = $self->{conn};
399         return unless $conn;
400         my $sort = shift;
401         my $call = $self->{call};
402         
403         for (@_) {
404 #               chomp;
405         my @lines = split /\n/;
406                 for (@lines) {
407                         $conn->send_now("$sort$call|$_");
408                         # debug log it, but not if it is a log message
409                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
410                 }
411         }
412         $self->{t} = time;
413 }
414
415 #
416 # send later with letter (more control)
417 #
418
419 sub send_later
420 {
421         my $self = shift;
422         my $conn = $self->{conn};
423         return unless $conn;
424         my $sort = shift;
425         my $call = $self->{call};
426         
427         for (@_) {
428 #               chomp;
429         my @lines = split /\n/;
430                 for (@lines) {
431                         $conn->send_later("$sort$call|$_");
432                         # debug log it, but not if it is a log message
433                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
434                 }
435         }
436         $self->{t} = time;
437 }
438
439 #
440 # the normal output routine
441 #
442 sub send                                                # this is always later and always data
443 {
444         my $self = shift;
445         my $conn = $self->{conn};
446         return unless $conn;
447         my $call = $self->{call};
448
449         foreach my $l (@_) {
450                 for (ref $l ? @$l : $l) {
451                         my @lines = split /\n/;
452                         for (@lines) {
453                                 $conn->send_later("D$call|$_");
454                                 dbg("-> D $call $_") if isdbg('chan');
455                         }
456                 }
457         }
458         $self->{t} = $main::systime;
459 }
460
461 # send a file (always later)
462 sub send_file
463 {
464         my ($self, $fn) = @_;
465         my $call = $self->{call};
466         my $conn = $self->{conn};
467         my @buf;
468   
469         open(F, $fn) or die "can't open $fn for sending file ($!)";
470         @buf = <F>;
471         close(F);
472         $self->send(@buf);
473 }
474
475 # this will implement language independence (in time)
476 sub msg
477 {
478         my $self = shift;
479         return DXM::msg($self->{lang}, @_);
480 }
481
482 # stick a broadcast on the delayed queue (but only up to 20 items)
483 sub delay
484 {
485         my $self = shift;
486         my $s = shift;
487         
488         $self->{delayed} = [] unless $self->{delayed};
489         push @{$self->{delayed}}, $s;
490         if (@{$self->{delayed}} >= 20) {
491                 shift @{$self->{delayed}};   # lose oldest one
492         }
493 }
494
495 # change the state of the channel - lots of scope for debugging here :-)
496 sub state
497 {
498         my $self = shift;
499         if (@_) {
500                 $self->{oldstate} = $self->{state};
501                 $self->{state} = shift;
502                 $self->{func} = '' unless defined $self->{func};
503                 dbg("$self->{call} channel func $self->{func} state $self->{oldstate} -> $self->{state}\n") if isdbg('state');
504
505                 # if there is any queued up broadcasts then splurge them out here
506                 if ($self->{delayed} && ($self->{state} eq 'prompt' || $self->{state} eq 'talk')) {
507                         $self->send (@{$self->{delayed}});
508                         delete $self->{delayed};
509                 }
510         }
511         return $self->{state};
512 }
513
514 # disconnect this channel
515 sub disconnect
516 {
517         my $self = shift;
518         my $user = $self->{user};
519         
520         $user->close($self->{startt}, $self->{hostname}) if defined $user;
521         $self->{conn}->disconnect if $self->{conn};
522         $self->del();
523 }
524
525 #
526 # just close all the socket connections down without any fiddling about, cleaning, being
527 # nice to other processes and otherwise telling them what is going on.
528 #
529 # This is for the benefit of forked processes to prepare for starting new programs, they
530 # don't want or need all this baggage.
531 #
532
533 sub closeall
534 {
535         my $ref;
536         foreach $ref (values %channels) {
537                 $ref->{conn}->disconnect() if $ref->{conn};
538         }
539 }
540
541 #
542 # Tell all the users that we have come in or out (if they want to know)
543 #
544 sub tell_login
545 {
546         my ($self, $m, $call) = @_;
547         
548         $call ||= $self->{call};
549         
550         # send info to all logged in thingies
551         my @dxchan = get_all_users();
552         my $dxchan;
553         foreach $dxchan (@dxchan) {
554                 next if $dxchan == $self;
555                 next if $dxchan->{call} eq $main::mycall;
556                 $dxchan->send($dxchan->msg($m, $call)) if $dxchan->{logininfo};
557         }
558 }
559
560 #
561 # Tell all the users if a buddy is logged or out
562 #
563 sub tell_buddies
564 {
565         my ($self, $m, $call, $node) = @_;
566         
567         $call ||= $self->{call};
568         $call =~ s/-\d+$//;
569         $m .= 'n' if $node;
570         
571         # send info to all logged in thingies
572         my @dxchan = get_all_users();
573         my $dxchan;
574         foreach $dxchan (@dxchan) {
575                 next if $dxchan == $self;
576                 next if $dxchan->{call} eq $main::mycall;
577                 $dxchan->send($dxchan->msg($m, $call, $node)) if grep $_ eq $call, @{$dxchan->{user}->{buddies}} ;
578         }
579 }
580
581 # various access routines
582
583 #
584 # return a list of valid elements 
585
586
587 sub fields
588 {
589         return keys(%valid);
590 }
591
592 #
593 # return a prompt for a field
594 #
595
596 sub field_prompt
597
598         my ($self, $ele) = @_;
599         return $valid{$ele};
600 }
601
602 # take a standard input message and decode it into its standard parts
603 sub decode_input
604 {
605         my $dxchan = shift;
606         my $data = shift;
607         my ($sort, $call, $line) = $data =~ /^([A-Z])(#?[A-Z0-9\/\-]{3,25})\|(.*)$/;
608
609         my $chcall = (ref $dxchan) ? $dxchan->call : "UN.KNOWN";
610         
611         # the above regexp must work
612         unless (defined $sort && defined $call && defined $line) {
613 #               $data =~ s/([\x00-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
614                 dbg("DUFF Line on $chcall: $data");
615                 return ();
616         }
617
618         if(ref($dxchan) && $call ne $chcall) {
619                 dbg("DUFF Line come in for $call on wrong channel $chcall");
620                 return();
621         }
622         
623         return ($sort, $call, $line);
624 }
625
626 # broadcast a message to all clusters taking into account isolation
627 # [except those mentioned after buffer]
628 sub broadcast_nodes
629 {
630         my $s = shift;                          # the line to be rebroadcast
631         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
632         my @dxchan = get_all_nodes();
633         my $dxchan;
634         
635         # send it if it isn't the except list and isn't isolated and still has a hop count
636         foreach $dxchan (@dxchan) {
637                 next if grep $dxchan == $_, @except;
638                 next if $dxchan == $main::me;
639                 
640                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
641
642                 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
643         }
644 }
645
646 # broadcast a message to all clusters ignoring isolation
647 # [except those mentioned after buffer]
648 sub broadcast_all_nodes
649 {
650         my $s = shift;                          # the line to be rebroadcast
651         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
652         my @dxchan = get_all_nodes();
653         my $dxchan;
654         
655         # send it if it isn't the except list and isn't isolated and still has a hop count
656         foreach $dxchan (@dxchan) {
657                 next if grep $dxchan == $_, @except;
658                 next if $dxchan == $main::me;
659
660                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
661                 $dxchan->send($routeit);
662         }
663 }
664
665 # broadcast to all users
666 # storing the spot or whatever until it is in a state to receive it
667 sub broadcast_users
668 {
669         my $s = shift;                          # the line to be rebroadcast
670         my $sort = shift;           # the type of transmission
671         my $fref = shift;           # a reference to an object to filter on
672         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
673         my @dxchan = get_all_users();
674         my $dxchan;
675         my @out;
676         
677         foreach $dxchan (@dxchan) {
678                 next if grep $dxchan == $_, @except;
679                 push @out, $dxchan;
680         }
681         broadcast_list($s, $sort, $fref, @out);
682 }
683
684
685 # broadcast to a list of users
686 sub broadcast_list
687 {
688         my $s = shift;
689         my $sort = shift;
690         my $fref = shift;
691         my $dxchan;
692         
693         foreach $dxchan (@_) {
694                 my $filter = 1;
695                 next if $dxchan == $main::me;
696                 
697                 if ($sort eq 'dx') {
698                     next unless $dxchan->{dx};
699                         ($filter) = $dxchan->{spotsfilter}->it($fref) if $dxchan->{spotsfilter} && ref $fref;
700                         next unless $filter;
701                 }
702                 next if $sort eq 'ann' && !$dxchan->{ann} && $s !~ /^To\s+LOCAL\s+de\s+(?:$main::myalias|$main::mycall)/i;
703                 next if $sort eq 'wwv' && !$dxchan->{wwv};
704                 next if $sort eq 'wcy' && !$dxchan->{wcy};
705                 next if $sort eq 'wx' && !$dxchan->{wx};
706
707                 $s =~ s/\a//og unless $dxchan->{beep};
708
709                 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
710                         $dxchan->send($s);      
711                 } else {
712                         $dxchan->delay($s);
713                 }
714         }
715 }
716
717 sub process_one
718 {
719         my $self = shift;
720
721         while (my $data = shift @{$self->{inqueue}}) {
722                 my ($sort, $call, $line) = $self->decode_input($data);
723                 next unless defined $sort;
724
725                 if ($sort ne 'D') {
726                         if (isdbg('chan')) {
727                                 if (($self->is_rbn && isdbg('rbnchan')) || !$self->is_rbn) {
728                                         dbg("<- $sort $call $line") if isdbg('chan'); # you may think this is tautology, but it's needed get the correct label on the debug line
729                                 }
730                         }
731                 }
732                 
733                 # handle A records
734                 my $user = $self->user;
735                 if ($sort eq 'I') {
736                         die "\$user not defined for $call" unless defined $user;
737                         
738                         # normal input
739                         $self->normal($line);
740                 } elsif ($sort eq 'G') {
741                         $self->enhanced($line);
742                 } elsif ($sort eq 'A' || $sort eq 'O' || $sort eq 'W') {
743                         $self->start($line, $sort);
744                 } elsif ($sort eq 'C') {
745                         $self->width($line); # change number of columns
746                 } elsif ($sort eq 'Z') {
747                         $self->disconnect;
748                 } elsif ($sort eq 'D') {
749                         ;                               # ignored (an echo)
750                 } else {
751                         dbg atime . " DXChannel::process_one: Unknown command letter ($sort) received from $call\n";
752                 }
753         }
754 }
755
756 sub process
757 {
758         foreach my $dxchan (values %channels) {
759                 next if $dxchan->{disconnecting};
760                 $dxchan->process_one;
761         }
762 }
763
764 sub handle_xml
765 {
766         my $self = shift;
767         my $r = 0;
768         
769         if (DXXml::available()) {
770                 $r = $self->{handle_xml} || 0;
771         } else {
772                 delete $self->{handle_xml} if exists $self->{handle_xml};
773         }
774         return $r;
775 }
776
777 sub error_handler
778 {
779         my $self = shift;
780         my $error = shift || '';
781         dbg("$self->{call} ERROR '$error', closing") if isdbg('chan');
782         $self->{conn}->set_error(undef) if exists $self->{conn};
783         $self->disconnect(1);
784 }
785
786 sub refresh_user
787 {
788         my $call = shift;
789         my $user = shift;
790         return unless $call && $user && ref $user;
791         my $self = DXChannel::get($call);
792         $self->{user} = $user;
793         return $user;
794 }
795
796 sub isregistered
797 {
798         my $self = shift;
799
800         # the sysop is registered!
801         return 1 if $self->{call} eq $main::myalias || $self->{call} eq $main::mycall;
802         
803         if ($main::reqreg) {
804                 return $self->{registered};
805         } else {
806                 return 1;
807         }
808 }
809
810 #no strict;
811 sub AUTOLOAD
812 {
813         no strict;
814         my $name = $AUTOLOAD;
815         return if $name =~ /::DESTROY$/;
816         $name =~ s/^.*:://o;
817   
818         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
819
820         # this clever line of code creates a subroutine which takes over from autoload
821         # from OO Perl - Conway
822         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
823         goto &$AUTOLOAD;
824 }
825
826
827 1;
828 __END__;