some detail changes to do with -w flags etc
[spider.git] / perl / DXCluster.pm
index 51c63f8239ed7af492148b68cf5f67007a5254af..8bd2c36ffb772eb5a24edab6b35d996dfc1c36f1 100644 (file)
@@ -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 
@@ -137,7 +171,7 @@ 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;
@@ -190,6 +224,8 @@ sub new
   my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
   $self->{pcversion} = $pcversion;
   $self->{list} = { } ;
+  $self->{mynode} = $self;   # for sh/station
+  $self->{users} = 0;
   $nodes++;
   dbg('cluster', "allocating node $call to cluster\n");
   return $self;
@@ -225,13 +261,15 @@ sub update_users
 {
   my $self = shift;
   my $count = shift;
-  $users -= $self->{users};
+  $count = 0 unless $count;
+  
+  $users -= $self->{users} if $self->{users};
   if ((keys %{$self->{list}})) {
     $self->{users} = (keys %{$self->{list}});
   } else {
     $self->{users} = $count;
   }
-  $users += $self->{users};
+  $users += $self->{users} if $self->{users};
   $maxusers = $users+$nodes if $users+$nodes > $maxusers;
 }