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);
60 $user = DXUser->new($call);
62 my $sort = $user->sort();
64 # is there one already connected?
65 if (DXChannel->get($call)) {
66 my $mess = DXM::msg('conother', $call);
67 dbg('chan', "-> D $call $mess\n");
68 $conn->send_now("D$call|$mess");
69 dbg('chan', "-> Z $call bye\n");
70 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
74 # is there one already connected elsewhere in the cluster?
75 if (DXCluster->get($call)) {
76 my $mess = DXM::msg('concluster', $call);
77 dbg('chan', "-> D $call $mess\n");
78 $conn->send_now("D$call|$mess");
79 dbg('chan', "-> Z $call bye\n");
80 $conn->send_now("Z$call|bye"); # this will cause 'client' to disconnect
84 # set some necessary flags on the user if they are connecting
85 $user->wwv(1) if !$user->wwv();
86 $user->talk(1) if !$user->talk();
87 $user->ann(1) if !$user->ann();
88 $user->here(1) if !$user->here();
89 $user->sort('U') if !$user->sort();
92 $dxchan = DXCommandmode->new($call, $conn, $user) if ($sort eq 'U');
93 $dxchan = DXProt->new($call, $conn, $user) if ($sort eq 'A');
94 die "Invalid sort of user on $call = $sort" if !$dxchan;
97 # queue the message and the channel object for later processing
99 my $self = bless {}, "inqueue";
100 $self->{dxchan} = $dxchan;
101 $self->{data} = $msg;
102 push @inqueue, $self;
111 # cease running this program, close down all the connections nicely
115 foreach $dxchan (DXChannel->get_all()) {
121 # this is where the input queue is dealt with and things are dispatched off to other parts of
125 my $self = shift @inqueue;
128 my $data = $self->{data};
129 my $dxchan = $self->{dxchan};
130 my ($sort, $call, $line) = $data =~ /^(\w)(\S+)\|(.*)$/;
132 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
133 dbg('chan', "<- $sort $call $line\n");
136 my $user = $dxchan->user;
138 $dxchan->start($line);
139 } elsif ($sort eq 'D') {
140 die "\$user not defined for $call" if !defined $user;
141 $dxchan->normal($line);
142 disconnect($dxchan) if ($dxchan->{state} eq 'bye');
143 } elsif ($sort eq 'Z') {
146 print STDERR atime, " Unknown command letter ($sort) received from $call\n";
150 #############################################################
152 # The start of the main line of code
154 #############################################################
156 # open the debug file, set various FHs to be unbuffered
161 STDOUT->autoflush(1);
163 # initialise User file system
164 DXUser->init($userfn);
166 # start listening for incoming messages/connects
167 Msg->new_server("$clusteraddr", $clusterport, \&login);
170 $SIG{'INT'} = \&cease;
171 $SIG{'TERM'} = \&cease;
172 $SIG{'HUP'} = 'IGNORE';
174 # this, such as it is, is the main loop!
177 Msg->event_loop(1, 0.001);
179 if ($timenow != $systime) {
184 process_inqueue(); # read in lines from the input queue and despatch them
185 DXCommandmode::process(); # process ongoing command mode stuff
186 DXProt::process(); # process ongoing ak1a pcxx stuff