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
23 use vars qw(%cluster %valid);
25 %cluster = (); # this is where we store the dxcluster database
28 mynode => '0,Parent Node,showcall',
30 confmode => '0,Conference Mode,yesno',
31 here => '0,Here?,yesno',
32 dxchan => '5,Channel ref',
33 pcversion => '5,Node Version',
34 list => '5,User List,dolist',
35 users => '0,No of Users',
40 my ($pkg, $dxchan, $call, $confmode, $here) = @_;
41 die "$call is already alloced" if $cluster{$call};
43 $self->{call} = $call;
44 $self->{confmode} = $confmode;
45 $self->{here} = $here;
46 $self->{dxchan} = $dxchan;
48 $cluster{$call} = bless $self, $pkg;
52 # get an entry exactly as it is
55 my ($pkg, $call) = @_;
60 # search for 'as is' only
61 return $cluster{$call};
65 # search for a call in the cluster
66 # taking into account SSIDs
70 my ($pkg, $call) = @_;
76 my $ref = $cluster{$call};
79 # search for the unSSIDed one
81 $ref = $cluster{$call};
84 # search for the SSIDed one
86 for ($i = 1; $i < 17; $i++) {
87 $ref = $cluster{"$call-$i"};
96 return values(%cluster);
99 # return a prompt for a field
102 my ($self, $ele) = @_;
106 # this expects a reference to a list in a node NOT a ref to a node
113 foreach $ref (@{$self}) {
114 my $s = $ref->{call};
115 $s = "($s)" if !$ref->{here};
122 # this expects a reference to a node
126 return $self->{call};
129 # the answer required by show/cluster
132 my $users = DXCommandmode::get_all();
133 my $uptime = main::uptime();
134 my $tot = $DXNode::users;
136 return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime";
142 dbg('cluster', "destroying $self->{call}\n");
149 my $name = $AUTOLOAD;
151 return if $name =~ /::DESTROY$/;
154 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
155 @_ ? $self->{$name} = shift : $self->{$name} ;
159 # USER special routines
164 @ISA = qw(DXCluster);
172 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
174 die "tried to add $call when it already exists" if DXCluster->get_exact($call);
176 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
177 $self->{mynode} = $node;
178 $node->add_user($call, $self);
179 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
186 my $call = $self->{call};
187 my $node = $self->{mynode};
189 $node->del_user($call);
190 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
195 return $DXNode::users; # + 1 for ME (naf eh!)
201 # NODE special routines
206 @ISA = qw(DXCluster);
211 use vars qw($nodes $users $maxusers);
220 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
221 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
222 $self->{pcversion} = $pcversion;
223 $self->{list} = { } ;
224 $self->{mynode} = $self; # for sh/station
227 dbg('cluster', "allocating node $call to cluster\n");
236 foreach $list (values(%DXCluster::cluster)) {
237 push @out, $list if $list->{pcversion};
245 my $call = $self->{call};
248 # delete all the listed calls
249 foreach $ref (values %{$self->{list}}) {
250 $ref->del(); # this also takes them out of this list
252 delete $DXCluster::cluster{$call}; # remove me from the cluster table
253 dbg('cluster', "deleting node $call from cluster\n");
254 $users -= $self->{users}; # it may be PC50 updated only therefore > 0
255 $users = 0 if $users < 0;
257 $nodes = 0 if $nodes < 0;
266 $self->{list}->{$call} = $ref; # add this user to the list on this node
267 $self->{users} = keys %{$self->{list}};
269 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
277 delete $self->{list}->{$call};
278 delete $DXCluster::cluster{$call}; # remove me from the cluster table
279 $self->{users} = keys %{$self->{list}};
281 $users = 0, warn "\$users gone neg, reset" if $users < 0;
282 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
289 $count = 0 unless $count;
291 $users -= $self->{users};
292 $self->{users} = $count unless keys %{$self->{list}};
293 $users += $self->{users};
294 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
299 return $nodes; # + 1 for ME!