+ $conn->to_connected($conn->{call}, 'O', $conn->{csort});
+ }
+ } elsif ($conn->{msg} =~ /\cJ/) {
+ my @lines = $conn->{msg} =~ /([^\cM\cJ]*)\cM?\cJ/g;
+ if ($conn->{msg} =~ /\cJ$/) {
+ delete $conn->{msg};
+ } else {
+ $conn->{msg} = pop @lines;
+ }
+ while (defined ($msg = shift @lines)) {
+ dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
+
+ $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
+
+ if ($conn->{state} eq 'C') {
+ &{$conn->{rproc}}($conn, "I$conn->{call}|$msg");
+ } elsif ($conn->{state} eq 'WL' ) {
+ $msg = uc $msg;
+ if (is_callsign($msg)) {
+ 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;
+ }
+ } elsif ($conn->{state} eq 'WC') {
+ if (exists $conn->{cmd} && @{$conn->{cmd}}) {
+ $conn->_docmd($msg);
+ if ($conn->{state} eq 'WC' && exists $conn->{cmd} && @{$conn->{cmd}} == 0) {
+ $conn->to_connected($conn->{call}, 'O', $conn->{csort});
+ }
+ }
+ }