2 # DX database control routines
4 # This manages the on-line cluster user 'database'
6 # This should all be pretty trees and things, but for now I
7 # just can't be bothered. If it becomes an issue I shall
10 # Copyright (c) 1998 - Dirk Koopman G1TLH
24 use vars qw(%cluster %valid);
26 %cluster = (); # this is where we store the dxcluster database
29 mynode => '0,Parent Node,DXCluster::showcall',
31 confmode => '0,Conference Mode,yesno',
32 here => '0,Here?,yesno',
33 dxchan => '5,Channel ref,DXCluster::showcall',
34 pcversion => '5,Node Version',
35 list => '5,User List,DXCluster::dolist',
36 users => '0,No of Users',
41 my ($pkg, $dxchan, $call, $confmode, $here) = @_;
42 die "$call is already alloced" if $cluster{$call};
44 $self->{call} = $call;
45 $self->{confmode} = $confmode;
46 $self->{here} = $here;
47 $self->{dxchan} = $dxchan;
49 $cluster{$call} = bless $self, $pkg;
53 # get an entry exactly as it is
56 my ($pkg, $call) = @_;
61 # search for 'as is' only
62 return $cluster{$call};
66 # search for a call in the cluster
67 # taking into account SSIDs
71 my ($pkg, $call) = @_;
77 my $ref = $cluster{$call};
80 # search for the unSSIDed one
82 $ref = $cluster{$call};
85 # search for the SSIDed one
87 for ($i = 1; $i < 17; $i++) {
88 $ref = $cluster{"$call-$i"};
97 return values(%cluster);
100 # return a prompt for a field
103 my ($self, $ele) = @_;
107 # return a list of valid elements
115 # this expects a reference to a list in a node NOT a ref to a node
122 foreach my $call (keys %{$self}) {
123 $ref = $$self{$call};
124 my $s = $ref->{call};
125 $s = "($s)" if !$ref->{here};
132 # this expects a reference to a node
136 return $self->{call};
139 # the answer required by show/cluster
142 my $users = DXCommandmode::get_all();
143 my $uptime = main::uptime();
144 my $tot = $DXNode::users;
146 return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime";
153 my $name = $AUTOLOAD;
155 return if $name =~ /::DESTROY$/;
158 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
159 @_ ? $self->{$name} = shift : $self->{$name} ;
163 # USER special routines
168 @ISA = qw(DXCluster);
176 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
178 die "tried to add $call when it already exists" if DXCluster->get_exact($call);
180 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
181 $self->{mynode} = $node;
182 $node->add_user($call, $self);
183 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
190 my $call = $self->{call};
191 my $node = $self->{mynode};
193 $node->del_user($call);
194 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
199 return $DXNode::users; # + 1 for ME (naf eh!)
205 # NODE special routines
210 @ISA = qw(DXCluster);
215 use vars qw($nodes $users $maxusers);
224 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
225 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
226 $self->{pcversion} = $pcversion;
227 $self->{list} = { } ;
228 $self->{mynode} = $self; # for sh/station
231 dbg('cluster', "allocating node $call to cluster\n");
240 foreach $list (values(%DXCluster::cluster)) {
241 push @out, $list if $list->{pcversion};
249 my $call = $self->{call};
252 # delete all the listed calls
253 foreach $ref (values %{$self->{list}}) {
254 $ref->del(); # this also takes them out of this list
256 delete $DXCluster::cluster{$call}; # remove me from the cluster table
257 dbg('cluster', "deleting node $call from cluster\n");
258 $users -= $self->{users}; # it may be PC50 updated only therefore > 0
259 $users = 0 if $users < 0;
261 $nodes = 0 if $nodes < 0;
270 $self->{list}->{$call} = $ref; # add this user to the list on this node
271 $self->{users} = keys %{$self->{list}};
273 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
281 delete $self->{list}->{$call};
282 delete $DXCluster::cluster{$call}; # remove me from the cluster table
283 $self->{users} = keys %{$self->{list}};
285 $users = 0, warn "\$users gone neg, reset" if $users < 0;
286 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
293 $count = 0 unless $count;
295 $users -= $self->{users};
296 $self->{users} = $count unless keys %{$self->{list}};
297 $users += $self->{users};
298 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
303 return $nodes; # + 1 for ME!
314 undef $self->{list} if $self->{list};