+ if ($dxchan->{gtk}) {
+ $dxchan->send_later('L', dd(['db', $s]));
+ } else {
+ $dxchan->send_later('L', $s);
+ }
+ }
+}
+
+sub do_entry_stuff
+{
+ my $self = shift;
+ my $line = shift;
+ my @out;
+
+ if ($self->state eq 'enterbody') {
+ my $loc = $self->{loc} || confess "local var gone missing" ;
+ if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
+ no strict 'refs';
+ push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
+ $self->func(undef);
+ $self->state('prompt');
+ } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
+ push @out, $self->msg('m10');
+ delete $loc->{lines};
+ delete $self->{loc};
+ $self->func(undef);
+ $self->state('prompt');
+ } else {
+ push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
+ # i.e. it ain't and end or abort, therefore store the line
+ }
+ } else {
+ confess "Invalid state $self->{state}";
+ }
+ return @out;
+}
+
+sub store_startup_script
+{
+ my $self = shift;
+ my $loc = $self->{loc} || confess "local var gone missing" ;
+ my @out;
+ my $call = $loc->{call} || confess "callsign gone missing";
+ confess "lines array gone missing" unless ref $loc->{lines};
+ my $r = Script::store($call, $loc->{lines});
+ if (defined $r) {
+ if ($r) {
+ push @out, $self->msg('m19', $call, $r);
+ } else {
+ push @out, $self->msg('m20', $call);
+ }
+ } else {
+ push @out, "error opening startup script $call $!";
+ }
+ return @out;
+}
+
+# Import any commands contained in any files in import_cmd directory
+#
+# If the filename has a recogisable callsign as some delimited part
+# of it, then this is the user the command will be run as.
+#
+sub import_cmd
+{
+ # are there any to do in this directory?
+ return unless -d $cmdimportdir;
+ unless (opendir(DIR, $cmdimportdir)) {
+ LogDbg('err', "can\'t open $cmdimportdir $!");
+ return;
+ }
+
+ my @names = readdir(DIR);
+ closedir(DIR);
+ my $name;
+
+ return unless @names;
+
+ foreach $name (@names) {
+ next if $name =~ /^\./;
+
+ my $s = Script->new($name, $cmdimportdir);
+ if ($s) {
+ LogDbg('DXCommand', "Run import cmd file $name");
+ my @cat = split /[^A-Za-z0-9]+/, $name;
+ my ($call) = grep {is_callsign(uc $_)} @cat;
+ $call ||= $main::mycall;
+ $call = uc $call;
+ my @out;
+
+
+ $s->inscript(0); # switch off script checks
+
+ if ($call eq $main::mycall) {
+ @out = $s->run($main::me, 1);
+ } else {
+ my $dxchan = DXChannel::get($call);
+ if ($dxchan) {
+ @out = $s->run($dxchan, 1);
+ } else {
+ my $u = DXUser::get($call);
+ if ($u) {
+ $dxchan = $main::me;
+ my $old = $dxchan->{call};
+ my $priv = $dxchan->{priv};
+ my $user = $dxchan->{user};
+ $dxchan->{call} = $call;
+ $dxchan->{priv} = $u->priv;
+ $dxchan->{user} = $u;
+ @out = $s->run($dxchan, 1);
+ $dxchan->{call} = $old;
+ $dxchan->{priv} = $priv;
+ $dxchan->{user} = $user;
+ } else {
+ LogDbg('err', "Trying to run import cmd for non-existant user $call");
+ }
+ }
+ }
+ $s->erase;
+ for (@out) {
+ LogDbg('DXCommand', "Import cmd $name/$call: $_");
+ }
+ } else {
+ LogDbg('err', "Failed to open $cmdimportdir/$name $!");
+ unlink "$cmdimportdir/$name";
+ }
+ }
+}
+
+sub print_find_reply
+{
+ my ($self, $node, $target, $flag, $ms) = @_;
+ my $sort = $flag == 2 ? "External" : "Local";
+ $self->send("$sort $target found at $node in $ms ms" );
+}
+
+# send the most relevant motd
+sub send_motd
+{
+ my $self = shift;
+ my $motd;
+
+ unless ($self->{registered}) {
+ $motd = "${main::motd}_nor_$self->{lang}";
+ $motd = "${main::motd}_nor" unless -e $motd;
+ }
+ $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
+ $motd = $main::motd unless $motd && -e $motd;
+ if ($self->conn->ax25) {
+ if ($motd) {
+ $motd = "${motd}_ax25" if -e "${motd}_ax25";
+ } else {
+ $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25";
+ }