my $sock = $conn->{sock};
return unless defined($sock);
push (@{$conn->{outqueue}}, $msg);
- dbg('connect', $msg) unless $conn->{state} eq 'C';
+ dbg('connect', "connect $conn->{cnum}: $msg") unless $conn->{state} eq 'C';
Msg::set_event_handler ($sock, "write" => sub {$conn->_send(0)});
}
if ($conn->{state} eq 'WC') {
if (exists $conn->{cmd}) {
if (@{$conn->{cmd}}) {
- dbg('connect', $conn->{msg});
+ dbg('connect', "connect $conn->{cnum}: $conn->{msg}");
$conn->_docmd($conn->{msg});
}
}
$conn->{msg} = pop @lines;
}
while (defined ($msg = shift @lines)) {
- dbg('connect', $msg) unless $conn->{state} eq 'C';
+ dbg('connect', "connect $conn->{cnum}: $msg") unless $conn->{state} eq 'C';
$msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
$msg =~ s/[\x00-\x08\x0a-\x19\x1b-\x1f\x80-\x9f]/./g; # immutable CSI sequence + control characters
} elsif ($conn->{state} eq 'WL' ) {
$msg = uc $msg;
if (is_callsign($msg)) {
- $conn->to_connected($msg, 'A', $conn->{csort});
+ my $sort = $conn->{csort};
+ $sort = 'local' if $conn->{peerhost} eq "127.0.0.1";
+ $conn->to_connected($msg, 'A', $sort);
} else {
$conn->send_now("Sorry $msg is an invalid callsign");
$conn->disconnect;
delete $conn->{cmd};
$conn->{timeout}->del if $conn->{timeout};
delete $conn->{timeout};
- $conn->_send_file("$main::data/connected");
&{$conn->{rproc}}($conn, "$dir$call|$sort");
+ $conn->_send_file("$main::data/connected");
}
sub new_client {
my $server_conn = shift;
my $sock = $server_conn->{sock}->accept();
- my $conn = $server_conn->new($server_conn->{rproc});
- $conn->{sock} = $sock;
-
- my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost} = $sock->peerhost(), $conn->{peerport} = $sock->peerport());
- if ($eproc) {
- $conn->{eproc} = $eproc;
- Msg::set_event_handler ($sock, "error" => $eproc);
+ if ($sock) {
+ my $conn = $server_conn->new($server_conn->{rproc});
+ $conn->{sock} = $sock;
+ Msg::blocking($sock, 0);
+ $conn->{blocking} = 0;
+ my $host;
+ eval {$host = $conn->{peerhost}};
+ my $port;
+ eval {$port = $conn->{peerport}} unless $@;
+ if ($@) {
+ $conn->disconnect;
+ } else {
+ my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost} = $host, $conn->{peerport} = $port);
+ dbg('connll', "accept $conn->{cnum} from $conn->{peerhost} $conn->{peerport}");
+ if ($eproc) {
+ $conn->{eproc} = $eproc;
+ Msg::set_event_handler ($sock, "error" => $eproc);
+ }
+ if ($rproc) {
+ $conn->{rproc} = $rproc;
+ my $callback = sub {$conn->_rcv};
+ Msg::set_event_handler ($sock, "read" => $callback);
+ # send login prompt
+ $conn->{state} = 'WL';
+ # $conn->send_raw("\xff\xfe\x01\xff\xfc\x01\ff\fd\x22");
+ # $conn->send_raw("\xff\xfa\x22\x01\x01\xff\xf0");
+ # $conn->send_raw("\xFF\xFC\x01");
+ $conn->_send_file("$main::data/issue");
+ $conn->send_raw("login: ");
+ $conn->_dotimeout(60);
+ } else {
+ &{$conn->{eproc}}() if $conn->{eproc};
+ $conn->disconnect();
+ }
+ }
+ } else {
+ dbg('err', "ExtMsg: error on accept ($!)");
}
- if ($rproc) {
- $conn->{rproc} = $rproc;
- my $callback = sub {$conn->_rcv};
- Msg::set_event_handler ($sock, "read" => $callback);
- # send login prompt
- $conn->{state} = 'WL';
-# $conn->send_raw("\xff\xfe\x01\xff\xfc\x01\ff\fd\x22");
-# $conn->send_raw("\xff\xfa\x22\x01\x01\xff\xf0");
-# $conn->send_raw("\xFF\xFC\x01");
- $conn->_send_file("$main::data/issue");
- $conn->send_raw("login: ");
- $conn->_dotimeout(60);
- } else {
- $conn->disconnect();
- }
}
sub start_connect
my $r;
$sort = lc $sort;
- dbg('connect', "CONNECT sort: $sort command: $line");
+ dbg('connect', "CONNECT $conn->{cnum} sort: $sort command: $line");
if ($sort eq 'telnet') {
# this is a straight network connect
my ($host, $port) = split /\s+/, $line;
$port = 23 if !$port;
$r = $conn->connect($host, $port);
if ($r) {
- dbg('connect', "Connected to $host $port");
+ dbg('connect', "Connected $conn->{cnum} to $host $port");
} else {
- dbg('connect', "***Connect Failed to $host $port $!");
+ dbg('connect', "***Connect $conn->{cnum} Failed to $host $port $!");
}
} elsif ($sort eq 'agw') {
# turn it into an AGW object
my $callback = sub {$conn->_rcv};
Msg::set_event_handler ($a, read => $callback);
}
- dbg('connect', "started pid: $conn->{pid} as $line");
+ dbg('connect', "connect $conn->{cnum}: started pid: $conn->{pid} as $line");
} else {
$^W = 0;
dbgclose();
*STDOUT = IO::File->new_from_fd($b, 'w') or die;
*STDERR = IO::File->new_from_fd($b, 'w') or die;
close $a;
- unless ($^O =~ /^MS/) {
+ unless ($main::is_win) {
# $SIG{HUP} = 'IGNORE';
$SIG{HUP} = $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = 'DEFAULT';
alarm(0);
{
my $conn = shift;
my $string = shift;
- dbg('connect', "abort $string");
+ dbg('connect', "connect $conn->{cnum}: abort $string");
$conn->{abort} = $string;
}
{
my $conn = shift;
my $val = shift;
- dbg('connect', "timeout set to $val");
+ dbg('connect', "connect $conn->{cnum}: timeout set to $val");
$conn->{timeout}->del if $conn->{timeout};
$conn->{timeval} = $val;
$conn->{timeout} = Timer->new($val, sub{ &_timedout($conn) });
{
my $conn = shift;
my $val = shift;
- dbg('connect', "lineend set to $val ");
+ dbg('connect', "connect $conn->{cnum}: lineend set to $val ");
$val =~ s/\\r/\r/g;
$val =~ s/\\n/\n/g;
$conn->{lineend} = $val;
if ($line) {
my ($expect, $send) = $cmd =~ /^\s*\'(.*)\'\s+\'(.*)\'/;
if ($expect) {
- dbg('connect', "expecting: \"$expect\" received: \"$line\"");
+ dbg('connect', "connect $conn->{cnum}: expecting: \"$expect\" received: \"$line\"");
if ($conn->{abort} && $line =~ /\Q$conn->{abort}/i) {
- dbg('connect', "aborted on /$conn->{abort}/");
+ dbg('connect', "connect $conn->{cnum}: aborted on /$conn->{abort}/");
$conn->disconnect;
delete $conn->{cmd};
return;
}
if ($line =~ /\Q$expect/i) {
- dbg('connect', "got: \"$expect\" sending: \"$send\"");
- $conn->send_later($send);
+ if (length $send) {
+ dbg('connect', "connect $conn->{cnum}: got: \"$expect\" sending: \"$send\"");
+ $conn->send_later("D$conn->{call}|$send");
+ }
delete $conn->{msg}; # get rid any input if a match
return;
}
sub _timedout
{
my $conn = shift;
- dbg('connect', "timed out after $conn->{timeval} seconds");
- $conn->{timeout}->del;
- delete $conn->{timeout};
+ dbg('connect', "connect $conn->{cnum}: timed out after $conn->{timeval} seconds");
$conn->disconnect;
}
$conn->conns($call);
$conn->{csort} = $f[1] if $f[1];
$conn->{state} = 'C';
- &{$conn->{rproc}}($conn, "O$call|telnet");
+ &{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
delete $conn->{cmd};
$conn->{timeout}->del if $conn->{timeout};
}
if ($f) {
while (<$f>) {
chomp;
- $conn->send_raw($_ . $conn->{lineend});
+ my $l = $_;
+ dbg('connll', "connect $conn->{cnum}: $l");
+ $conn->send_raw($l . $conn->{lineend});
}
$f->close;
}