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