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 # search for a call in the cluster
55 my ($pkg, $call) = @_;
56 return $cluster{$call};
62 return values(%cluster);
65 # return a prompt for a field
68 my ($self, $ele) = @_;
72 # this expects a reference to a list in a node NOT a ref to a node
79 foreach $ref (@{$self}) {
81 $s = "($s)" if !$ref->{here};
88 # this expects a reference to a node
95 # the answer required by show/cluster
98 my $users = DXCommandmode::get_all();
99 my $uptime = main::uptime();
100 my $tot = $DXNode::users + 1;
102 return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime";
108 dbg('cluster', "destroying $self->{call}\n");
115 my $name = $AUTOLOAD;
117 return if $name =~ /::DESTROY$/;
120 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
121 @_ ? $self->{$name} = shift : $self->{$name} ;
125 # USER special routines
130 @ISA = qw(DXCluster);
138 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
140 die "tried to add $call when it already exists" if DXCluster->get($call);
142 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
143 $self->{mynode} = $node;
144 $node->{list}->{$call} = $self; # add this user to the list on this node
145 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
153 my $call = $self->{call};
154 my $node = $self->{mynode};
156 delete $node->{list}->{$call};
157 delete $DXCluster::cluster{$call}; # remove me from the cluster table
158 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
164 return $DXNode::users; # + 1 for ME (naf eh!)
170 # NODE special routines
175 @ISA = qw(DXCluster);
180 use vars qw($nodes $users $maxusers);
189 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
190 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
191 $self->{pcversion} = $pcversion;
192 $self->{list} = { } ;
194 dbg('cluster', "allocating node $call to cluster\n");
203 foreach $list (values(%DXCluster::cluster)) {
204 push @out, $list if $list->{pcversion};
212 my $call = $self->{call};
215 # delete all the listed calls
216 foreach $ref (values %{$self->{list}}) {
217 $ref->del(); # this also takes them out of this list
219 delete $DXCluster::cluster{$call}; # remove me from the cluster table
220 dbg('cluster', "deleting node $call from cluster\n");
221 $nodes-- if $nodes > 0;
228 $users -= $self->{users};
229 if ((keys %{$self->{list}})) {
230 $self->{users} = (keys %{$self->{list}});
232 $self->{users} = $count;
234 $users += $self->{users};
235 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
240 return $nodes; # + 1 for ME!