1. I believe I have fixed all the login/logout 'broken pipe' errors
[spider.git] / perl / cluster.pl
index 7b5bf6f46b95a55728789e00728bfd61eab0c6c1..5d6248efa296ab372364f9ddb684e3de8c3c2149 100755 (executable)
@@ -58,17 +58,20 @@ use Bands;
 use Geomag;
 use CmdAlias;
 use Filter;
-use Local;
 use DXDb;
-use Data::Dumper;
+use AnnTalk;
+use WCY;
 
+use Data::Dumper;
 use Fcntl ':flock'; 
 
+use Local;
+
 package main;
 
 @inqueue = ();                                 # the main input queue, an array of hashes
 $systime = 0;                                  # the time now (in seconds)
-$version = "1.40";                             # the version no of the software
+$version = "1.41";                             # the version no of the software
 $starttime = 0;                 # the starting time of the cluster   
 $lockfn = "cluster.lock";       # lock file name
 @outstanding_connects = ();     # list of outstanding connects
@@ -103,6 +106,11 @@ sub rec
        
        if (!defined $msg || (defined $err && $err)) {
                if ($dxchan) {
+                       if (defined $err) {
+                               $conn->disconnect;
+                               undef $conn;
+                               $dxchan->conn(undef);
+                       }
                        $dxchan->disconnect;
                } elsif ($conn) {
                        $conn->disconnect;
@@ -117,18 +125,18 @@ sub rec
                # is there one already connected to me - locally? 
                my $user = DXUser->get($call);
                if (DXChannel->get($call)) {
-                       my $mess = DXM::msg($lang, ($user && $user->sort eq 'A') ? 'concluster' : 'conother', $call);
+                       my $mess = DXM::msg($lang, ($user && $user->is_node) ? 'concluster' : 'conother', $call);
                        already_conn($conn, $call, $mess);
                        return;
                }
                
                # is there one already connected elsewhere in the cluster?
                if ($user) {
-                       if (($user->sort eq 'A' || $call eq $myalias) && !DXCluster->get_exact($call)) {
+                       if (($user->is_node || $call eq $myalias) && !DXCluster->get_exact($call)) {
                                ;
                        } else {
                                if (DXCluster->get_exact($call)) {
-                                       my $mess = DXM::msg($lang, $user->sort eq 'A' ? 'concluster' : 'conother', $call);
+                                       my $mess = DXM::msg($lang, $user->is_node ? 'concluster' : 'conother', $call);
                                        already_conn($conn, $call, $mess);
                                        return;
                                }
@@ -151,9 +159,9 @@ sub rec
                }
 
                # create the channel
-               $dxchan = DXCommandmode->new($call, $conn, $user) if ($user->sort eq 'U');
-               $dxchan = DXProt->new($call, $conn, $user) if ($user->sort eq 'A');
-               $dxchan = BBS->new($call, $conn, $user) if ($user->sort eq 'B');
+               $dxchan = DXCommandmode->new($call, $conn, $user) if $user->is_user;
+               $dxchan = DXProt->new($call, $conn, $user) if $user->is_node;
+               $dxchan = BBS->new($call, $conn, $user) if $user->is_bbs;
                die "Invalid sort of user on $call = $sort" if !$dxchan;
        }
        
@@ -186,7 +194,7 @@ sub cease
 
        # disconnect nodes
        foreach $dxchan (DXChannel->get_all()) {
-               next unless $dxchan->is_ak1a;
+               next unless $dxchan->is_node;
                disconnect($dxchan) unless $dxchan == $DXProt::me;
        }
        Msg->event_loop(1, 0.05);
@@ -198,7 +206,7 @@ sub cease
 
        # disconnect users
        foreach $dxchan (DXChannel->get_all()) {
-               next if $dxchan->is_ak1a;
+               next if $dxchan->is_node;
                disconnect($dxchan) unless $dxchan == $DXProt::me;
        }
        Msg->event_loop(1, 0.05);
@@ -238,7 +246,7 @@ sub process_inqueue
        
        my $data = $self->{data};
        my $dxchan = $self->{dxchan};
-       my ($sort, $call, $line) = $data =~ /^(\w)([A-Z0-9\-]+)\|(.*)$/;
+       my ($sort, $call, $line) = $data =~ /^(\w)([^\|]+)\|(.*)$/;
        my $error;
        
        # the above regexp must work
@@ -299,7 +307,7 @@ STDOUT->autoflush(1);
 Log('cluster', "DXSpider V$version started");
 
 # banner
-dbg('err', "DXSpider DX Cluster Version $version\nCopyright (c) 1998-1999 Dirk Koopman G1TLH");
+dbg('err', "DXSpider DX Cluster Version $version", "Copyright (c) 1998-2000 Dirk Koopman G1TLH");
 
 # load Prefixes
 dbg('err', "loading prefixes ...");
@@ -331,6 +339,7 @@ CmdAlias->init();
 
 # initialise the Geomagnetic data engine
 Geomag->init();
+WCY->init();
 
 # initial the Spot stuff
 Spot->init();
@@ -368,10 +377,14 @@ dbg('local', "Local::init error $@") if $@;
 
 # this, such as it is, is the main loop!
 dbg('err', "orft we jolly well go ...");
-Log('err', "DXSpider version $version started...");
 
 #open(DB::OUT, "|tee /tmp/aa");
 
+$SIG{PIPE} = sub { 
+       #$DB::single = 1;  
+       dbg('err', "Broken PIPE signal received"); 
+};
+
 for (;;) {
        my $timenow;
 #      $DB::trace = 1;