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
28 @inqueue = (); # the main input queue, an array of hashes
29 $systime = 0; # the time now (in seconds)
31 # handle disconnections
35 return if !defined $dxchan;
36 my $user = $dxchan->{user};
37 my $conn = $dxchan->{conn};
39 $user->close() if defined $user;
40 $conn->disconnect() if defined $conn;
44 # handle incoming messages
47 my ($conn, $msg, $err) = @_;
48 my $dxchan = DXChannel->get_by_cnum($conn); # get the dxconnnect object for this message
50 if (defined $err && $err) {
51 disconnect($dxchan) if defined $dxchan;
55 # set up the basic channel info - this needs a bit more thought - there is duplication here
56 if (!defined $dxchan) {
57 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
58 my $user = DXUser->get($call);
59 $user = DXUser->new($call) if !defined $user;
60 $user->sort('U') if (!$user->sort());
61 my $sort = $user->sort();
63 # is there one already connected?
64 if (DXChannel->get($call)) {
65 my $mess = DXM::msg('conother', $call);
66 dbg('chan', "-> D $call $mess\n");
67 $conn->send_now("D$call|$mess");
68 dbg('chan', "-> Z $call bye\n");
69 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
73 # is there one already connected elsewhere in the cluster?
74 if (DXCluster->get($call)) {
75 my $mess = DXM::msg('concluster', $call);
76 dbg('chan', "-> D $call $mess\n");
77 $conn->send_now("D$call|$mess");
78 dbg('chan', "-> Z $call bye\n");
79 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
84 $dxchan = DXCommandmode->new($call, $conn, $user) if ($sort eq 'U');
85 $dxchan = DXProt->new($call, $conn, $user) if ($sort eq 'A');
86 die "Invalid sort of user on $call = $sort" if !$dxchan;
89 # queue the message and the channel object for later processing
91 my $self = bless {}, "inqueue";
92 $self->{dxchan} = $dxchan;
103 # cease running this program, close down all the connections nicely
107 foreach $dxchan (DXChannel->get_all()) {
113 # this is where the input queue is dealt with and things are dispatched off to other parts of
117 my $self = shift @inqueue;
120 my $data = $self->{data};
121 my $dxchan = $self->{dxchan};
122 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
124 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
125 dbg('chan', "<- $sort $call $line\n");
128 my $user = $dxchan->user;
130 $dxchan->start($line);
131 } elsif ($sort eq 'D') {
132 die "\$user not defined for $call" if !defined $user;
133 $dxchan->normal($line);
134 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
135 } elsif ($sort eq 'Z') {
138 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
142 #############################################################
144 # The start of the main line of code
146 #############################################################
148 # open the debug file, set various FHs to be unbuffered
153 STDOUT->autoflush(1);
155 # initialise User file system
156 DXUser->init($userfn);
158 # start listening for incoming messages/connects
159 Msg->new_server("$clusteraddr", $clusterport, \&login);
162 $SIG{'INT'} = \&cease;
163 $SIG{'TERM'} = \&cease;
164 $SIG{'HUP'} = 'IGNORE';
166 # this, such as it is, is the main loop!
169 Msg->event_loop(1, 0.001);
171 if ($timenow != $systime) {
176 process_inqueue(); # read in lines from the input queue and despatch them
177 DXCommandmode::process(); # process ongoing command mode stuff
178 DXProt::process(); # process ongoing ak1a pcxx stuff