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