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";
44 @inqueue = (); # the main input queue, an array of hashes
45 $systime = 0; # the time now (in seconds)
46 $version = 1.3; # the version no of the software
48 # handle disconnections
52 return if !defined $dxchan;
53 $dxchan->disconnect();
56 # handle incoming messages
59 my ($conn, $msg, $err) = @_;
60 my $dxchan = DXChannel->get_by_cnum($conn); # get the dxconnnect object for this message
62 if (defined $err && $err) {
63 disconnect($dxchan) if defined $dxchan;
67 # set up the basic channel info - this needs a bit more thought - there is duplication here
68 if (!defined $dxchan) {
69 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
71 # is there one already connected?
72 if (DXChannel->get($call)) {
73 my $mess = DXM::msg($lang, 'conother', $call);
74 dbg('chan', "-> D $call $mess\n");
75 $conn->send_now("D$call|$mess");
77 dbg('chan', "-> Z $call bye\n");
78 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
82 # is there one already connected elsewhere in the cluster?
83 if (DXCluster->get($call)) {
84 my $mess = DXM::msg($lang, 'concluster', $call);
85 dbg('chan', "-> D $call $mess\n");
86 $conn->send_now("D$call|$mess");
88 dbg('chan', "-> Z $call bye\n");
89 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
93 my $user = DXUser->get($call);
95 $user = DXUser->new($call);
97 $user->{lang} = $main::lang if !$user->{lang}; # to autoupdate old systems
102 $dxchan = DXCommandmode->new($call, $conn, $user) if ($user->sort eq 'U');
103 $dxchan = DXProt->new($call, $conn, $user) if ($user->sort eq 'A');
104 die "Invalid sort of user on $call = $sort" if !$dxchan;
107 # queue the message and the channel object for later processing
109 my $self = bless {}, "inqueue";
110 $self->{dxchan} = $dxchan;
111 $self->{data} = $msg;
112 push @inqueue, $self;
121 # cease running this program, close down all the connections nicely
125 foreach $dxchan (DXChannel->get_all()) {
131 # this is where the input queue is dealt with and things are dispatched off to other parts of
135 my $self = shift @inqueue;
138 my $data = $self->{data};
139 my $dxchan = $self->{dxchan};
140 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
142 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
143 dbg('chan', "<- $sort $call $line\n");
146 my $user = $dxchan->user;
148 $dxchan->start($line);
149 } elsif ($sort eq 'D') {
150 die "\$user not defined for $call" if !defined $user;
153 $dxchan->normal($line);
155 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
156 } elsif ($sort eq 'Z') {
159 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
163 #############################################################
165 # The start of the main line of code
167 #############################################################
169 # open the debug file, set various FHs to be unbuffered
174 STDOUT->autoflush(1);
177 print "DXSpider DX Cluster Version $version\nCopyright (c) 1998 Dirk Koopman G1TLH\n";
180 print "loading prefixes ...\n";
184 print "loading band data ...\n";
187 # initialise User file system
188 print "loading user file system ...\n";
189 DXUser->init($userfn);
191 # start listening for incoming messages/connects
192 print "starting listener ...\n";
193 Msg->new_server("$clusteraddr", $clusterport, \&login);
196 $SIG{'INT'} = \&cease;
197 $SIG{'TERM'} = \&cease;
198 $SIG{'HUP'} = 'IGNORE';
200 # read in system messages
203 # read in command aliases
206 # initialise the protocol engine
209 # initialise the Geomagnetic data engine
212 # initial the Spot stuff
215 # put in a DXCluster node for us here so we can add users and take them away
216 DXNode->new(0, $mycall, 0, 1, $DXProt::myprot_version);
218 # read in any existing message headers
219 print "reading existing message headers\n";
222 # read in any cron jobs
223 print "reading cron jobs\n";
226 # this, such as it is, is the main loop!
227 print "orft we jolly well go ...\n";
230 Msg->event_loop(1, 0.001);
232 process_inqueue(); # read in lines from the input queue and despatch them
234 # do timed stuff, ongoing processing happens one a second
235 if ($timenow != $systime) {
239 DXCommandmode::process(); # process ongoing command mode stuff
240 DXProt::process(); # process ongoing ak1a pcxx stuff
242 DXConnect::process();