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