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
21 use vars qw(%cluster %valid);
23 %cluster = (); # this is where we store the dxcluster database
26 mynode => '0,Parent Node,DXCluster::showcall',
28 confmode => '0,Conference Mode,yesno',
29 here => '0,Here?,yesno',
30 dxchan => '5,Channel ref,DXCluster::showcall',
31 pcversion => '5,Node Version',
32 list => '5,User List,DXCluster::dolist',
33 users => '0,No of Users',
38 my ($pkg, $dxchan, $call, $confmode, $here) = @_;
39 die "$call is already alloced" if $cluster{$call};
41 $self->{call} = $call;
42 $self->{confmode} = $confmode;
43 $self->{here} = $here;
44 $self->{dxchan} = $dxchan;
46 $cluster{$call} = bless $self, $pkg;
50 # get an entry exactly as it is
53 my ($pkg, $call) = @_;
58 # search for 'as is' only
59 return $cluster{$call};
63 # search for a call in the cluster
64 # taking into account SSIDs
68 my ($pkg, $call) = @_;
74 my $ref = $cluster{$call};
77 # search for the unSSIDed one
79 $ref = $cluster{$call};
82 # search for the SSIDed one
84 for ($i = 1; $i < 17; $i++) {
85 $ref = $cluster{"$call-$i"};
94 return values(%cluster);
97 # return a prompt for a field
100 my ($self, $ele) = @_;
104 # return a list of valid elements
112 # this expects a reference to a list in a node NOT a ref to a node
119 foreach my $call (keys %{$self}) {
120 $ref = $$self{$call};
121 my $s = $ref->{call};
122 $s = "($s)" if !$ref->{here};
129 # this expects a reference to a node
133 return $self->{call};
136 # the answer required by show/cluster
139 my $users = DXCommandmode::get_all();
140 my $uptime = main::uptime();
141 my $tot = $DXNode::users;
143 return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime";
150 my $name = $AUTOLOAD;
152 return if $name =~ /::DESTROY$/;
155 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
156 @_ ? $self->{$name} = shift : $self->{$name} ;
160 # USER special routines
165 @ISA = qw(DXCluster);
173 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
175 die "tried to add $call when it already exists" if DXCluster->get_exact($call);
177 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
178 $self->{mynode} = $node;
179 $node->add_user($call, $self);
180 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
187 my $call = $self->{call};
188 my $node = $self->{mynode};
190 $node->del_user($call);
191 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
196 return $DXNode::users; # + 1 for ME (naf eh!)
202 # NODE special routines
207 @ISA = qw(DXCluster);
212 use vars qw($nodes $users $maxusers);
221 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
222 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
223 $self->{pcversion} = $pcversion;
224 $self->{list} = { } ;
225 $self->{mynode} = $self; # for sh/station
228 dbg('cluster', "allocating node $call to cluster\n");
237 foreach $list (values(%DXCluster::cluster)) {
238 push @out, $list if $list->{pcversion};
246 my $call = $self->{call};
249 # delete all the listed calls
250 foreach $ref (values %{$self->{list}}) {
251 $ref->del(); # this also takes them out of this list
253 delete $DXCluster::cluster{$call}; # remove me from the cluster table
254 dbg('cluster', "deleting node $call from cluster\n");
255 $users -= $self->{users}; # it may be PC50 updated only therefore > 0
256 $users = 0 if $users < 0;
258 $nodes = 0 if $nodes < 0;
267 $self->{list}->{$call} = $ref; # add this user to the list on this node
268 $self->{users} = keys %{$self->{list}};
270 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
278 delete $self->{list}->{$call};
279 delete $DXCluster::cluster{$call}; # remove me from the cluster table
280 $self->{users} = keys %{$self->{list}};
282 $users = 0, warn "\$users gone neg, reset" if $users < 0;
283 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
290 $count = 0 unless $count;
292 $users -= $self->{users};
293 $self->{users} = $count unless keys %{$self->{list}};
294 $users += $self->{users};
295 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
300 return $nodes; # + 1 for ME!
311 undef $self->{list} if $self->{list};