X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCluster.pm;h=0eb98a4bbbe46575c2e5ae76cb1a3971030dc918;hb=337f38bfac57a5e5df34c63094fb869b0e2f6bee;hp=3f2eda8e5c034b9b76944810ee08018d52e4e7bd;hpb=0824a94355e5fb2b4c379bb013d66466725629f5;p=spider.git diff --git a/perl/DXCluster.pm b/perl/DXCluster.pm index 3f2eda8e..0eb98a4b 100644 --- a/perl/DXCluster.pm +++ b/perl/DXCluster.pm @@ -16,8 +16,8 @@ package DXCluster; use Exporter; @ISA = qw(Exporter); -use Carp; use DXDebug; +use Carp; use strict; use vars qw(%cluster %valid); @@ -49,11 +49,45 @@ sub alloc return $self; } +# get an entry exactly as it is +sub get_exact +{ + my ($pkg, $call) = @_; + + # belt and braces + $call = uc $call; + + # search for 'as is' only + return $cluster{$call}; +} + +# # search for a call in the cluster +# taking into account SSIDs +# sub get { my ($pkg, $call) = @_; - return $cluster{$call}; + + # belt and braces + $call = uc $call; + + # search for 'as is' + my $ref = $cluster{$call}; + return $ref if $ref; + + # search for the unSSIDed one + $call =~ s/-\d+$//o; + $ref = $cluster{$call}; + return $ref if $ref; + + # search for the SSIDed one + my $i; + for ($i = 1; $i < 17; $i++) { + $ref = $cluster{"$call-$i"}; + return $ref if $ref; + } + return undef; } # get all @@ -92,6 +126,16 @@ sub showcall return $self->{call}; } +# the answer required by show/cluster +sub cluster +{ + my $users = DXCommandmode::get_all(); + my $uptime = main::uptime(); + my $tot = $DXNode::users + 1; + + return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime"; +} + sub DESTROY { my $self = shift; @@ -122,20 +166,16 @@ package DXNodeuser; use DXDebug; use strict; -use vars qw($users); - -$users = 0; sub new { my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_; - die "tried to add $call when it already exists" if DXCluster->get($call); + die "tried to add $call when it already exists" if DXCluster->get_exact($call); my $self = $pkg->alloc($dxchan, $call, $confmode, $here); $self->{mynode} = $node; $node->{list}->{$call} = $self; # add this user to the list on this node - $users++; dbg('cluster', "allocating user $call to $node->{call} in cluster\n"); $node->update_users; return $self; @@ -151,12 +191,11 @@ sub del delete $DXCluster::cluster{$call}; # remove me from the cluster table dbg('cluster', "deleting user $call from $node->{call} in cluster\n"); $node->update_users; - $users-- if $users > 0; } sub count { - return $users; # + 1 for ME (naf eh!) + return $DXNode::users; # + 1 for ME (naf eh!) } no strict; @@ -172,9 +211,12 @@ package DXNode; use DXDebug; use strict; -use vars qw($nodes); +use vars qw($nodes $users $maxusers); $nodes = 0; +$users = 0; +$maxusers = 0; + sub new { @@ -182,6 +224,7 @@ sub new my $self = $pkg->alloc($dxchan, $call, $confmode, $here); $self->{pcversion} = $pcversion; $self->{list} = { } ; + $self->{mynode} = $self; # for sh/station $nodes++; dbg('cluster', "allocating node $call to cluster\n"); return $self; @@ -216,11 +259,15 @@ sub del sub update_users { my $self = shift; - if (%{$self->{list}}) { - $self->{users} = scalar %{$self->{list}}; + my $count = shift; + $users -= $self->{users}; + if ((keys %{$self->{list}})) { + $self->{users} = (keys %{$self->{list}}); } else { - $self->{users} = shift; + $self->{users} = $count; } + $users += $self->{users}; + $maxusers = $users+$nodes if $users+$nodes > $maxusers; } sub count