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 = 1; # 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
30 # cease communications
34 if (defined $conn && $sendz) {
35 $conn->send_now("Z$call|bye...\n");
40 # terminate program from signal
46 # handle incoming messages
49 my ($con, $msg, $err) = @_;
50 if (defined $err && $err) {
54 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)|(.*)$/;
57 $nl = "" if $mode == 0;
58 $line =~ s/\n/\r/o if $mode == 1;
60 } elsif ($sort eq 'M') {
61 $mode = $line; # set new mode from cluster
62 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
77 $r = sysread($fh, $buf, 1024);
78 # print "sys: $r $buf";
81 $buf =~ s/\r/\n/o if $mode == 1;
82 $dangle = !($buf =~ /\n$/);
83 @lines = split /\n/, $buf;
84 if ($dangle) { # pull off any dangly bits
89 $first = shift @lines;
90 unshift @lines, ($lastbit . $first) if ($first);
91 foreach $first (@lines) {
92 $conn->send_now("D$call|$first");
96 $conn->send_now("D$call|$buf");
104 die "client.pl <call> [<mode>]\r\n" if (!$call);
105 $mode = $ARGV[1] if (@ARGV > 1);
112 select STDOUT; $| = 1;
114 $SIG{'INT'} = \&sig_term;
115 $SIG{'TERM'} = \&sig_term;
116 #$SIG{'HUP'} = \&sig_term;
118 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
119 $conn->send_now("A$call|start");
120 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);