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 # this clever line of code creates a subroutine which takes over from autoload
157 # from OO Perl - Conway
158 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$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};