fiz console.pl resizing
[spider.git] / perl / DXChannel.pm
index e386d0849e2b5330c53a8727d1511d0eb065640f..f2a1638cdf0c101817bc92a8aa22c795472bf43b 100644 (file)
@@ -21,7 +21,7 @@
 #
 # Copyright (c) 1998-2000 - Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 package DXChannel;
 
@@ -35,7 +35,7 @@ use Prefix;
 use Route;
 
 use strict;
-use vars qw(%channels %valid @ISA $count);
+use vars qw(%channels %valid @ISA $count $maxerrors);
 
 %channels = ();
 $count = 0;
@@ -80,11 +80,13 @@ $count = 0;
                  wcyfilter => '5,WCY Filt-out',
                  spotsfilter => '5,Spot Filt-out',
                  routefilter => '5,Route Filt-out',
+                 pc92filter => '5,PC92 Route Filt-out',
                  inannfilter => '5,Ann Filt-inp',
                  inwwvfilter => '5,WWV Filt-inp',
                  inwcyfilter => '5,WCY Filt-inp',
                  inspotsfilter => '5,Spot Filt-inp',
                  inroutefilter => '5,Route Filt-inp',
+                 inpc92filter => '5,PC92 Route Filt-inp',
                  passwd => '9,Passwd List,yesno',
                  pingint => '5,Ping Interval ',
                  nopings => '5,Ping Obs Count',
@@ -121,8 +123,11 @@ $count = 0;
                  handle_xml => '9,Handles XML,yesno',
                  do_pc9x => '9,Handles PC9x,yesno',
                  inqueue => '9,Input Queue,parray',
+                 next_pc92_update => '9,Next PC92 Update,atime',
+                 next_pc92_keepalive => '9,Next PC92 KeepAlive,atime',
                 );
 
+$maxerrors = 20;                               # the maximum number of concurrent errors allowed before disconnection
 
 # object destruction
 sub DESTROY
@@ -154,12 +159,15 @@ sub alloc
                $user->new_buddies unless $user->buddies;
                $self->{group} = $user->group;
                $self->{sort} = $user->sort;
+               $self->{width} = $user->width;
        }
        $self->{startt} = $self->{t} = time;
        $self->{state} = 0;
        $self->{oldstate} = 0;
        $self->{lang} = $main::lang if !$self->{lang};
        $self->{func} = "";
+       $self->{width} ||=  80;
+       
 
        # add in all the dxcc, itu, zone info
        my @dxcc = Prefix::extract($call);
@@ -176,6 +184,22 @@ sub alloc
        return $channels{$call} = $self;
 }
 
+# count errors and disconnect if too many
+# this has to be here because it can come from rcmd (DXProt) as
+# well as DXCommandmode.
+sub _error_out
+{
+       my $self = shift;
+       my $e = shift;
+       if (++$self->{errors} > $maxerrors) {
+               $self->send($self->msg('e26'));
+               $self->disconnect;
+               return ();
+       } else {
+               return ($self->msg($e));
+       }
+}
+
 # rebless this channel as something else
 sub rebless
 {
@@ -220,6 +244,17 @@ sub get_all_nodes
        return @out;
 }
 
+# return a list of node calls
+sub get_all_node_calls
+{
+       my $ref;
+       my @out;
+       foreach $ref (values %channels) {
+               push @out, $ref->{call} if $ref->is_node;
+       }
+       return @out;
+}
+
 # return a list of all users
 sub get_all_users
 {
@@ -573,28 +608,6 @@ sub decode_input
        return ($sort, $call, $line);
 }
 
-sub rspfcheck
-{
-       my ($self, $flag, $node, $user) = @_;
-       my $nref = Route::Node::get($node);
-       my $dxchan = $nref->dxchan if $nref;
-       if ($nref && $dxchan) {
-           if ($dxchan == $self) {
-                       return 1 unless $user;
-                       return 1 if $user eq $node;
-                       my @users = $nref->users;
-                       return 1 if @users == 0 || grep $user eq $_, @users;
-                       dbg("RSPF: $user not on $node") if isdbg('chanerr');
-               } else {
-                       dbg("RSPF: Shortest path for $node is " . $nref->dxchan->{call}) if isdbg('chanerr');
-               }
-       } else {
-               return 1 if $flag;
-               dbg("RSPF: required $node not found" ) if isdbg('chanerr');
-       }
-       return 0;
-}
-
 # broadcast a message to all clusters taking into account isolation
 # [except those mentioned after buffer]
 sub broadcast_nodes
@@ -689,17 +702,14 @@ sub broadcast_list
 sub process
 {
        foreach my $dxchan (get_all()) {
-
+               next if $dxchan->{disconnecting};
+               
                while (my $data = shift @{$dxchan->{inqueue}}) {
                        my ($sort, $call, $line) = $dxchan->decode_input($data);
                        next unless defined $sort;
 
                        # do the really sexy console interface bit! (Who is going to do the TK interface then?)
                        dbg("<- $sort $call $line") if $sort ne 'D' && isdbg('chan');
-                       if ($dxchan->{disconnecting}) {
-                               dbg('In disconnection, ignored');
-                               next;
-                       }
 
                        # handle A records
                        my $user = $dxchan->user;
@@ -714,6 +724,8 @@ sub process
                                $dxchan->disconnect;
                        } elsif ($sort eq 'D') {
                                ;                               # ignored (an echo)
+                       } elsif ($sort eq 'C') {
+                               $dxchan->width($line); # change number of columns
                        } elsif ($sort eq 'G') {
                                $dxchan->enhanced($line);
                        } else {
@@ -736,6 +748,20 @@ sub handle_xml
        return $r;
 }
 
+sub registered
+{
+       my $self = shift;
+
+       # the sysop is registered!
+       return 1 if $self->call eq $main::myalias || $self->call eq $main::mycall;
+       
+       if ($main::reqreg) {
+               return $self->{registered};
+       } else {
+               return 1;
+       }
+}
+
 #no strict;
 sub AUTOLOAD
 {