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',
28 confmode => '0,Conference Mode,yesno',
29 here => '0,Here?,yesno',
30 dxchancall => '5,Channel Call',
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->{dxchancall} = $dxchan->call;
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";
152 $self->{mynode} = $noderef->call;
154 $noderef = DXCluster->get_exact($self->{mynode});
156 my $mynode = $self->{mynode};
157 my $call = $self->{call};
158 dbg('err', "parent node $mynode has disappeared from $call" );
170 $self->{dxchancall} = $dxchan->call;
172 $dxchan = DXChannel->get($self->{dxchancall});
174 my $dxcall = $self->{dxchancall};
175 my $call = $self->{call};
176 dbg('err', "parent dxchan $dxcall has disappeared from $call" );
186 my $name = $AUTOLOAD;
188 return if $name =~ /::DESTROY$/;
191 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
192 # this clever line of code creates a subroutine which takes over from autoload
193 # from OO Perl - Conway
194 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
195 @_ ? $self->{$name} = shift : $self->{$name} ;
199 # USER special routines
204 @ISA = qw(DXCluster);
212 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
214 die "tried to add $call when it already exists" if DXCluster->get_exact($call);
216 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
217 $self->{mynode} = $node->call;
218 $node->add_user($call, $self);
219 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
226 my $call = $self->{call};
227 my $node = $self->mynode;
229 $node->del_user($call);
230 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
235 return $DXNode::users; # + 1 for ME (naf eh!)
241 # NODE special routines
246 @ISA = qw(DXCluster);
251 use vars qw($nodes $users $maxusers);
260 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
261 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
262 $self->{pcversion} = $pcversion;
263 $self->{list} = { } ;
264 $self->{mynode} = $self->call; # for sh/station
267 dbg('cluster', "allocating node $call to cluster\n");
276 foreach $list (values(%DXCluster::cluster)) {
277 push @out, $list if $list->{pcversion};
285 my $call = $self->{call};
288 # delete all the listed calls
289 foreach $ref (values %{$self->{list}}) {
290 $ref->del(); # this also takes them out of this list
292 delete $DXCluster::cluster{$call}; # remove me from the cluster table
293 dbg('cluster', "deleting node $call from cluster\n");
294 $users -= $self->{users}; # it may be PC50 updated only therefore > 0
295 $users = 0 if $users < 0;
297 $nodes = 0 if $nodes < 0;
306 $self->{list}->{$call} = $ref; # add this user to the list on this node
307 $self->{users} = keys %{$self->{list}};
309 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
317 delete $self->{list}->{$call};
318 delete $DXCluster::cluster{$call}; # remove me from the cluster table
319 $self->{users} = keys %{$self->{list}};
321 $users = 0, warn "\$users gone neg, reset" if $users < 0;
322 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
329 $count = 0 unless $count;
331 $users -= $self->{users};
332 $self->{users} = $count unless keys %{$self->{list}};
333 $users += $self->{users};
334 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
339 return $nodes; # + 1 for ME!
350 undef $self->{list} if $self->{list};