3 # This is the DX cluster 'daemon'. It sits in the middle of its little
4 # web of client routines sucking and blowing data where it may.
6 # Hence the name of 'spider' (although it may become 'dxspider')
8 # Copyright (c) 1998 Dirk Koopman G1TLH
13 # make sure that modules are searched in the order local then perl
15 # root of directory tree for this system
17 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
19 unshift @INC, "$root/perl"; # this IS the right way round!
20 unshift @INC, "$root/local";
23 # $Exporter::Verbose = 1;
49 @inqueue = (); # the main input queue, an array of hashes
50 $systime = 0; # the time now (in seconds)
51 $version = "1.11"; # the version no of the software
52 $starttime = 0; # the starting time of the cluster
54 # handle disconnections
58 return if !defined $dxchan;
59 $dxchan->disconnect();
62 # handle incoming messages
65 my ($conn, $msg, $err) = @_;
66 my $dxchan = DXChannel->get_by_cnum($conn); # get the dxconnnect object for this message
68 if (defined $err && $err) {
69 disconnect($dxchan) if defined $dxchan;
73 # set up the basic channel info - this needs a bit more thought - there is duplication here
74 if (!defined $dxchan) {
75 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
77 # is there one already connected?
78 if (DXChannel->get($call)) {
79 my $mess = DXM::msg($lang, 'conother', $call);
80 dbg('chan', "-> D $call $mess\n");
81 $conn->send_now("D$call|$mess");
83 dbg('chan', "-> Z $call bye\n");
84 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
88 # is there one already connected elsewhere in the cluster (and not a cluster)
89 my $user = DXUser->get($call);
90 if ($user && $user->sort eq 'A' && !DXCluster->get_exact($call)) {
92 } elsif (($call eq $main::myalias && DXCluster->get_exact($call)) ||
93 DXCluster->get($call)) {
94 my $mess = DXM::msg($lang, 'concluster', $call);
95 dbg('chan', "-> D $call $mess\n");
96 $conn->send_now("D$call|$mess");
98 dbg('chan', "-> Z $call bye\n");
99 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
103 # the user MAY have an SSID if local, but otherwise doesn't
104 my $user = DXUser->get($call);
105 if (!defined $user) {
106 $user = DXUser->new($call);
108 $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems
112 if ($user->lockout) {
113 Log('DXCommand', "$call is locked out, disconnected");
114 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
119 $dxchan = DXCommandmode->new($call, $conn, $user) if ($user->sort eq 'U');
120 $dxchan = DXProt->new($call, $conn, $user) if ($user->sort eq 'A');
121 die "Invalid sort of user on $call = $sort" if !$dxchan;
124 # queue the message and the channel object for later processing
126 my $self = bless {}, "inqueue";
127 $self->{dxchan} = $dxchan;
128 $self->{data} = $msg;
129 push @inqueue, $self;
138 # cease running this program, close down all the connections nicely
142 foreach $dxchan (DXChannel->get_all()) {
145 Log('cluster', "DXSpider V$version stopped");
149 # the reaper of children
155 # this is where the input queue is dealt with and things are dispatched off to other parts of
159 my $self = shift @inqueue;
162 my $data = $self->{data};
163 my $dxchan = $self->{dxchan};
164 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
166 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
167 dbg('chan', "<- $sort $call $line\n") unless $sort eq 'D';
170 my $user = $dxchan->user;
171 if ($sort eq 'A' || $sort eq 'O') {
172 $dxchan->start($line, $sort);
173 } elsif ($sort eq 'I') {
174 die "\$user not defined for $call" if !defined $user;
177 $dxchan->normal($line);
179 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
180 } elsif ($sort eq 'Z') {
182 } elsif ($sort eq 'D') {
183 ; # ignored (an echo)
185 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
191 my $t = $systime - $starttime;
192 my $days = int $t / 86400;
194 my $hours = int $t / 3600;
196 my $mins = int $t / 60;
197 return sprintf "%d %02d:%02d", $days, $hours, $mins;
199 #############################################################
201 # The start of the main line of code
203 #############################################################
205 $starttime = $systime = time;
207 # open the debug file, set various FHs to be unbuffered
211 STDOUT->autoflush(1);
213 Log('cluster', "DXSpider V$version started");
216 print "DXSpider DX Cluster Version $version\nCopyright (c) 1998 Dirk Koopman G1TLH\n";
219 print "loading prefixes ...\n";
223 print "loading band data ...\n";
226 # initialise User file system
227 print "loading user file system ...\n";
228 DXUser->init($userfn);
230 # start listening for incoming messages/connects
231 print "starting listener ...\n";
232 Msg->new_server("$clusteraddr", $clusterport, \&login);
235 $SIG{'INT'} = \&cease;
236 $SIG{'TERM'} = \&cease;
237 $SIG{'HUP'} = 'IGNORE';
238 $SIG{'CHLD'} = \&reap;
240 # read in system messages
243 # read in command aliases
246 # initialise the protocol engine
249 # initialise the Geomagnetic data engine
252 # initial the Spot stuff
255 # put in a DXCluster node for us here so we can add users and take them away
256 DXNode->new(0, $mycall, 0, 1, $DXProt::myprot_version);
258 # read in any existing message headers and clean out old crap
259 print "reading existing message headers\n";
263 # read in any cron jobs
264 print "reading cron jobs\n";
267 # this, such as it is, is the main loop!
268 print "orft we jolly well go ...\n";
271 Msg->event_loop(1, 0.001);
273 process_inqueue(); # read in lines from the input queue and despatch them
275 # do timed stuff, ongoing processing happens one a second
276 if ($timenow != $systime) {
280 DXCron::process(); # do cron jobs
281 DXCommandmode::process(); # process ongoing command mode stuff
282 DXProt::process(); # process ongoing ak1a pcxx stuff
283 DXConnect::process();
286 last if --$decease <= 0;