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
16 unshift @INC, "/spider/local";
17 unshift @INC, "/spider/perl";
23 $mode = 2; # 1 - \n = \r as EOL, 2 - \n = \n, 0 - transparent
24 $call = ""; # the callsign being used
25 @stdoutq = (); # the queue of stuff to send out to the user
26 $conn = 0; # the connection object for the cluster
27 $lastbit = ""; # the last bit of an incomplete input line
28 $mynl = "\n"; # standard terminator
30 # cease communications
34 if (defined $conn && $sendz) {
35 $conn->send_now("Z$call|bye...\n");
40 # terminate program from signal
56 # handle incoming messages
59 my ($con, $msg, $err) = @_;
60 if (defined $err && $err) {
64 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
68 $snl = "" if $mode == 0;
69 $snl = ' ' if ($mode && $line =~ />$/);
70 $line =~ s/\n/\r/og if $mode == 1;
71 #my $p = qq($line$snl);
73 } elsif ($sort eq 'M') {
74 $mode = $line; # set new mode from cluster
76 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
91 $r = sysread($fh, $buf, 1024);
92 # print "sys: $r $buf";
95 $buf =~ s/\r/\n/og if $mode == 1;
96 $dangle = !($buf =~ /\n$/);
97 @lines = split /\n/, $buf;
98 if ($dangle) { # pull off any dangly bits
103 $first = shift @lines;
104 unshift @lines, ($lastbit . $first) if ($first);
105 foreach $first (@lines) {
106 $conn->send_now("D$call|$first");
110 $conn->send_now("D$call|$buf");
117 $call = uc shift @ARGV;
118 $call = uc $mycall if !$call;
119 $connsort = lc shift @ARGV;
120 $connsort = 'local' if !$connsort;
121 $mode = ($connsort =~ /^ax/) ? 1 : 2;
124 #select STDOUT; $| = 1;
125 STDOUT->autoflush(1);
127 $SIG{'INT'} = \&sig_term;
128 $SIG{'TERM'} = \&sig_term;
129 $SIG{'HUP'} = \&sig_term;
131 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
132 $conn->send_now("A$call|$connsort");
133 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);