mega-merge of major parts of mojo
[spider.git] / cmd / send.pl
index 71cea2bc7f7d0616ac8234516dcda53597e9069e..0fb91e10bc7ed3799f8f1014c50fe790b3304976 100644 (file)
 # 
 # Copyright (c) Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 my ($self, $line) = @_;
-return (1, $self->msg('e5')) if $self->remotecmd;
+return (1, $self->msg('e5')) if $self->remotecmd || $self->inscript;
+return (1, $self->msg('e36')) unless $self->state =~ /^prompt/;
 
 my @out;
 my $loc = $self->{loc} = {};
@@ -32,11 +33,13 @@ $loc->{rrreq} = '0';
 
 if ($self->state eq "prompt") {
 
-       my @f = split /\b/, $line;
+       my @f = split /([\s\@\$,])/, $line;
        @f = map {s/\s+//g; length $_ ? $_ : ()} @f;
+       @f = grep {$_ ne ','} @f;
        
        # any thing after send?
        return (1, $self->msg('e6')) if !@f;
+       return (1, $self->msg('e28')) unless $self->isregistered || uc $f[0] eq $main::myalias;
 
        while (@f) {
                my $f = uc shift @f; 
@@ -108,28 +111,40 @@ if ($self->state eq "prompt") {
                        # callsign ?
                        $notincalls = 0;
 
+#                      $DB::single = 1;
+                       
                        # is this callsign a distro?
-                       my $fn = "/spider/msg/distro/$f.pl";
-                       if (-e $fn) {
-                               my $fh = new IO::File $fn;
-                               if ($fh) {
-                                       local $/ = undef;
-                                       my $s = <$fh>;
-                                       $fh->close;
-                                       my @call;
-                                       @call = eval $s;
-                                       return (1, "Error in Distro $f.pl:", $@) if $@;
-                                       if (@call > 0) {
-                                               push @f, @call;
-                                               next;
+                       # but be careful about messages to 'sysop'
+                       if ($self->priv < 5 && $f eq 'SYSOP') {
+                               push @to, $main::myalias;
+                               $loc->{private} = 1;
+                       } else {
+                               my $fn = "/spider/msg/distro/$f.pl";
+                               if (-e $fn) {
+                                       my $fh = new IO::File $fn;
+                                       if ($fh) {
+                                               local $/ = undef;
+                                               my $s = <$fh>;
+                                               $fh->close;
+                                               my @call;
+                                               @call = eval $s;
+                                               return (1, "Error in Distro $f.pl:", $@) if $@;
+                                               if (@call > 0) {
+                                                       push @f, @call;
+                                                       next;
+                                               }
                                        }
                                }
                        }
 
-                       if (grep $_ eq $f, @DXMsg::badmsg) {
-                               push @out, $self->msg('m3', $f);
+                       if (($loc->{private} && is_callsign($f)) || (!$loc->{private} && DXMsg::valid_bull_addr($f))) {
+                               if (grep $_ eq $f, @DXMsg::badmsg) {
+                                       push @out, $self->msg('m3', $f);
+                               } else {
+                                       push @to, $f;
+                               }
                        } else {
-                               push @to, $f;
+                               push @out, $self->msg('m3', $f);
                        }
                }
        }
@@ -139,7 +154,7 @@ if ($self->state eq "prompt") {
                $loc->{to} = \@to;
        } else {
                delete $self->{loc};
-               return (1, $self->msg('e6'));
+               return (1, @out, $self->msg('e6'));
        }
        $loc->{from} ||= $self->call;
        unless (is_callsign($loc->{from})) {