3 # A thing that implements dxcluster 'protocol'
5 # This is a perl module/program that sits on the end of a dxcluster
6 # 'protocol' connection and deals with anything that might come along.
8 # this program is called by ax25d and gets raw ax25 text on its input
10 # Copyright (c) 1998 Dirk Koopman G1TLH
26 @inqueue = (); # the main input queue, an array of hashes
27 $systime = 0; # the time now (in seconds)
29 # handle disconnections
33 return if !defined $dxchan;
34 my $user = $dxchan->{user};
35 my $conn = $dxchan->{conn};
37 $user->close() if defined $user;
38 $conn->disconnect() if defined $conn;
42 # handle incoming messages
45 my ($conn, $msg, $err) = @_;
46 my $dxchan = DXChannel->get_by_cnum($conn); # get the dxconnnect object for this message
48 if (defined $err && $err) {
49 disconnect($dxchan) if defined $dxchan;
53 # set up the basic channel info - this needs a bit more thought - there is duplication here
54 if (!defined $dxchan) {
55 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
56 my $user = DXUser->get($call);
57 $user = DXUser->new($call) if !defined $user;
58 $user->sort('U') if (!$user->sort());
59 my $sort = $user->sort();
60 $dxchan = DXCommandmode->new($call, $conn, $user) if ($sort eq 'U');
61 $dxchan = DXProt->new($call, $conn, $user) if ($sort eq 'A');
62 die "Invalid sort of user on $call = $sort" if !$dxchan;
65 # queue the message and the channel object for later processing
67 my $self = bless {}, "inqueue";
68 $self->{dxchan} = $dxchan;
79 # cease running this program, close down all the connections nicely
83 foreach $dxchan (DXChannel->get_all()) {
89 # this is where the input queue is dealt with and things are dispatched off to other parts of
93 my $self = shift @inqueue;
96 my $data = $self->{data};
97 my $dxchan = $self->{dxchan};
98 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
100 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
101 print DEBUG atime, " <- $sort $call $line\n" if defined DEBUG;
102 print "<- $sort $call $line\n";
105 my $user = $dxchan->user;
107 $dxchan->start($line);
108 } elsif ($sort eq 'D') {
109 die "\$user not defined for $call" if !defined $user;
110 $dxchan->normal($line);
111 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
112 } elsif ($sort eq 'Z') {
115 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
119 #############################################################
121 # The start of the main line of code
123 #############################################################
125 # open the debug file, set various FHs to be unbuffered
126 open(DEBUG, ">>$debugfn") or die "can't open $debugfn($!)";
127 select DEBUG; $| = 1;
128 select STDOUT; $| = 1;
130 # initialise User file system
131 DXUser->init($userfn);
133 # start listening for incoming messages/connects
134 Msg->new_server("$clusteraddr", $clusterport, \&login);
137 $SIG{'INT'} = \&cease;
138 $SIG{'TERM'} = \&cease;
139 $SIG{'HUP'} = 'IGNORE';
141 # this, such as it is, is the main loop!
144 Msg->event_loop(1, 0.001);
146 if ($timenow != $systime) {
151 process_inqueue(); # read in lines from the input queue and despatch them
152 DXCommandmode::process(); # process ongoing command mode stuff
153 DXProt::process(); # process ongoing ak1a pcxx stuff