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;
48 @inqueue = (); # the main input queue, an array of hashes
49 $systime = 0; # the time now (in seconds)
50 $version = 1.4; # the version no of the software
52 # handle disconnections
56 return if !defined $dxchan;
57 $dxchan->disconnect();
60 # handle incoming messages
63 my ($conn, $msg, $err) = @_;
64 my $dxchan = DXChannel->get_by_cnum($conn); # get the dxconnnect object for this message
66 if (defined $err && $err) {
67 disconnect($dxchan) if defined $dxchan;
71 # set up the basic channel info - this needs a bit more thought - there is duplication here
72 if (!defined $dxchan) {
73 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
75 # is there one already connected?
76 if (DXChannel->get($call)) {
77 my $mess = DXM::msg($lang, 'conother', $call);
78 dbg('chan', "-> D $call $mess\n");
79 $conn->send_now("D$call|$mess");
81 dbg('chan', "-> Z $call bye\n");
82 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
86 # is there one already connected elsewhere in the cluster?
87 if (DXCluster->get($call)) {
88 my $mess = DXM::msg($lang, 'concluster', $call);
89 dbg('chan', "-> D $call $mess\n");
90 $conn->send_now("D$call|$mess");
92 dbg('chan', "-> Z $call bye\n");
93 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
97 my $user = DXUser->get($call);
99 $user = DXUser->new($call);
101 $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems
106 $dxchan = DXCommandmode->new($call, $conn, $user) if ($user->sort eq 'U');
107 $dxchan = DXProt->new($call, $conn, $user) if ($user->sort eq 'A');
108 die "Invalid sort of user on $call = $sort" if !$dxchan;
111 # queue the message and the channel object for later processing
113 my $self = bless {}, "inqueue";
114 $self->{dxchan} = $dxchan;
115 $self->{data} = $msg;
116 push @inqueue, $self;
125 # cease running this program, close down all the connections nicely
129 foreach $dxchan (DXChannel->get_all()) {
132 Log('cluster', "DXSpider V$version stopped");
136 # this is where the input queue is dealt with and things are dispatched off to other parts of
140 my $self = shift @inqueue;
143 my $data = $self->{data};
144 my $dxchan = $self->{dxchan};
145 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
147 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
148 dbg('chan', "<- $sort $call $line\n");
151 my $user = $dxchan->user;
153 $dxchan->start($line);
154 } elsif ($sort eq 'D') {
155 die "\$user not defined for $call" if !defined $user;
158 $dxchan->normal($line);
160 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
161 } elsif ($sort eq 'Z') {
164 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
168 #############################################################
170 # The start of the main line of code
172 #############################################################
174 # open the debug file, set various FHs to be unbuffered
178 STDOUT->autoflush(1);
180 Log('cluster', "DXSpider V$version started");
183 print "DXSpider DX Cluster Version $version\nCopyright (c) 1998 Dirk Koopman G1TLH\n";
186 print "loading prefixes ...\n";
190 print "loading band data ...\n";
193 # initialise User file system
194 print "loading user file system ...\n";
195 DXUser->init($userfn);
197 # start listening for incoming messages/connects
198 print "starting listener ...\n";
199 Msg->new_server("$clusteraddr", $clusterport, \&login);
202 $SIG{'INT'} = \&cease;
203 $SIG{'TERM'} = \&cease;
204 $SIG{'HUP'} = 'IGNORE';
206 # read in system messages
209 # read in command aliases
212 # initialise the protocol engine
215 # initialise the Geomagnetic data engine
218 # initial the Spot stuff
221 # put in a DXCluster node for us here so we can add users and take them away
222 DXNode->new(0, $mycall, 0, 1, $DXProt::myprot_version);
224 # read in any existing message headers
225 print "reading existing message headers\n";
228 # read in any cron jobs
229 print "reading cron jobs\n";
232 # this, such as it is, is the main loop!
233 print "orft we jolly well go ...\n";
236 Msg->event_loop(1, 0.001);
238 process_inqueue(); # read in lines from the input queue and despatch them
240 # do timed stuff, ongoing processing happens one a second
241 if ($timenow != $systime) {
245 DXCron::process(); # do cron jobs
246 DXCommandmode::process(); # process ongoing command mode stuff
247 DXProt::process(); # process ongoing ak1a pcxx stuff
248 DXConnect::process();