X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcluster.pl;h=32f90d88ded118a462f2b75bc247352d3d23c726;hb=97d5445b1e468d9228367640421b2f90ac021224;hp=0caade5c98da91c243181658bc17ce1b58e5c233;hpb=7dfcb79db379b97452ba1bde654a1945718eb7df;p=spider.git diff --git a/perl/cluster.pl b/perl/cluster.pl index 0caade5c..32f90d88 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -10,6 +10,8 @@ # $Id$ # +require 5.004; + # make sure that modules are searched in the order local then perl BEGIN { # root of directory tree for this system @@ -48,7 +50,7 @@ package main; @inqueue = (); # the main input queue, an array of hashes $systime = 0; # the time now (in seconds) -$version = 1.8; # the version no of the software +$version = "1.13"; # the version no of the software $starttime = 0; # the starting time of the cluster # handle disconnections @@ -59,6 +61,18 @@ sub disconnect $dxchan->disconnect(); } +# send a message to call on conn and disconnect +sub already_conn +{ + my ($conn, $call, $mess) = @_; + + dbg('chan', "-> D $call $mess\n"); + $conn->send_now("D$call|$mess"); + sleep(1); + dbg('chan', "-> Z $call bye\n"); + $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect +} + # handle incoming messages sub rec { @@ -74,41 +88,35 @@ sub rec if (!defined $dxchan) { my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/; - # is there one already connected? - if (DXChannel->get($call)) { - my $mess = DXM::msg($lang, 'conother', $call); - dbg('chan', "-> D $call $mess\n"); - $conn->send_now("D$call|$mess"); - sleep(1); - dbg('chan', "-> Z $call bye\n"); - $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect - return; - } - # is there one already connected elsewhere in the cluster (and not a cluster) my $user = DXUser->get($call); - if ($user && $user->sort eq 'A' && !DXCluster->get_exact($call)) { - ; - } elsif (($call eq $main::myalias && DXCluster->get_exact($call)) || - DXCluster->get($call)) { - my $mess = DXM::msg($lang, 'concluster', $call); - dbg('chan', "-> D $call $mess\n"); - $conn->send_now("D$call|$mess"); - sleep(1); - dbg('chan', "-> Z $call bye\n"); + if ($user) { + if (($user->sort eq 'A' || $call == $myalias) && !DXCluster->get_exact($call)) { + ; + } else { + if (DXCluster->get($call) || DXChannel->get($call)) { + my $mess = DXM::msg($lang, $user->sort eq 'A' ? 'concluster' : 'conother', $call); + already_conn($conn, $call, $mess); + return; + } + } + $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems + } else { + if (DXCluster->get($call)) { + my $mess = DXM::msg($lang, 'conother', $call); + already_conn($conn, $call, $mess); + return; + } + $user = DXUser->new($call); + } + + # is he locked out ? + if ($user->lockout) { + Log('DXCommand', "$call is locked out, disconnected"); $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect return; } - - # the user MAY have an SSID if local, but otherwise doesn't - my $user = DXUser->get($call); - if (!defined $user) { - $user = DXUser->new($call); - } else { - $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems - } - - + # 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'); @@ -134,7 +142,7 @@ sub cease { my $dxchan; foreach $dxchan (DXChannel->get_all()) { - disconnect($dxchan); + disconnect($dxchan) unless $dxchan == $DXProt::me; } Log('cluster', "DXSpider V$version stopped"); exit(0); @@ -158,13 +166,13 @@ sub process_inqueue my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/; # do the really sexy console interface bit! (Who is going to do the TK interface then?) - dbg('chan', "<- $sort $call $line\n"); + dbg('chan', "<- $sort $call $line\n") unless $sort eq 'D'; # handle A records my $user = $dxchan->user; if ($sort eq 'A' || $sort eq 'O') { $dxchan->start($line, $sort); - } elsif ($sort eq 'D') { + } elsif ($sort eq 'I') { die "\$user not defined for $call" if !defined $user; # normal input @@ -173,6 +181,8 @@ sub process_inqueue disconnect($dxchan) if ($dxchan->{state} eq 'bye'); } elsif ($sort eq 'Z') { disconnect($dxchan); + } elsif ($sort eq 'D') { + ; # ignored (an echo) } else { print STDERR atime, " Unknown command letter ($sort) received from $call\n"; }