fiddle about with 'bye'
[spider.git] / perl / DXCommandmode.pm
index ac0fb62470a942cf5c8d95830d7ff77b02507385..c03885526a9ed96664d31f75e31a7995eac48bf8 100644 (file)
@@ -85,13 +85,11 @@ sub start
 
        $self->{name} = $name ? $name : $call;
        $self->send($self->msg('l2',$self->{name}));
-       $self->send_file($main::motd) if (-e $main::motd);
        $self->state('prompt');         # a bit of room for further expansion, passwords etc
        $self->{priv} = $user->priv || 0;
        $self->{lang} = $user->lang || $main::lang || 'en';
        $self->{pagelth} = $user->pagelth || 20;
-       $self->{priv} = 0 if $line =~ /^(ax|te)/; # set the connection priv to 0 - can be upgraded later
-       ($self->{width}) = $line =~ /width=(\d+)/;
+       ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
        $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
        $self->{consort} = $line;       # save the connection type
        
@@ -107,6 +105,24 @@ sub start
        $self->{ann_talk} = $user->wantann_talk;
        $self->{here} = 1;
 
+       # sort out registration
+       if ($main::reqreg == 1) {
+               $self->{registered} = $user->registered;
+       } elsif ($main::reqreg == 2) {
+               $self->{registered} = !$user->registered;
+       } else {
+               $self->{registered} = 1;
+       }
+
+
+       # decide which motd to send
+       my $motd = "${main::motd}_nor" unless $self->{registered};
+       $motd = $main::motd unless $motd && -e $motd;
+       $self->send_file($motd) if -e $motd;
+
+       # sort out privilege reduction
+       $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
+
        # get the filters
        $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'user_default', 0);
        $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'user_default', 0);
@@ -123,9 +139,11 @@ sub start
        }
 
        # decide on echo
-       if (!$user->wantecho) {
+       my $echo = $user->wantecho;
+       unless ($echo) {
                $self->send_now('E', "0");
                $self->send($self->msg('echow'));
+               $self->conn->echo($echo) if $self->conn->can('echo');
        }
        
        $self->tell_login('loginu');
@@ -195,8 +213,8 @@ sub normal
                }
        } elsif ($self->{state} eq 'sysop') {
                my $passwd = $self->{user}->passwd;
-               my @pw = split / */, $passwd;
                if ($passwd) {
+                       my @pw = grep {$_ !~ /\s/} split //, $passwd;
                        my @l = @{$self->{passwd}};
                        my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
                        if ($cmdline =~ /$str/) {
@@ -207,7 +225,31 @@ sub normal
                } else {
                        $self->send($self->msg('sorry'));
                }
-               delete $self->{passwd};
+               $self->state('prompt');
+       } elsif ($self->{state} eq 'passwd') {
+               my $passwd = $self->{user}->passwd;
+               if ($passwd && $cmdline eq $passwd) {
+                       $self->send($self->msg('pw1'));
+                       $self->state('passwd1');
+               } else {
+                       $self->conn->{echo} = $self->conn->{decho};
+                       delete $self->conn->{decho};
+                       $self->send($self->msg('sorry'));
+                       $self->state('prompt');
+               }
+       } elsif ($self->{state} eq 'passwd1') {
+               $self->{passwd} = $cmdline;
+               $self->send($self->msg('pw2'));
+               $self->state('passwd2');
+       } elsif ($self->{state} eq 'passwd2') {
+               if ($cmdline eq $self->{passwd}) {
+                       $self->{user}->passwd($cmdline);
+                       $self->send($self->msg('pw3'));
+               } else {
+                       $self->send($self->msg('pw4'));
+               }
+               $self->conn->{echo} = $self->conn->{decho};
+               delete $self->conn->{decho};
                $self->state('prompt');
        } elsif ($self->{state} eq 'talk') {
                if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
@@ -222,8 +264,14 @@ sub normal
                        $self->send($self->talk_prompt);
                } elsif ($self->{talklist} && @{$self->{talklist}}) {
                        # send what has been said to whoever is in this person's talk list
-                       for (@{$self->{talklist}}) {
-                               $self->send_talks($_, $cmdline);
+                       my @bad;
+                       if (@bad = BadWords::check($cmdline)) {
+                               $self->badcount(($self->badcount||0) + @bad);
+                               Log('DXCommand', "$self->{call} swore: $cmdline");
+                       } else {
+                               for (@{$self->{talklist}}) {
+                                       $self->send_talks($_, $cmdline);
+                               }
                        }
                        $self->send($self->talk_prompt) if $self->{state} eq 'talk';
                } else {
@@ -238,7 +286,12 @@ sub normal
                } else {
                        eval {  @ans = &{$self->{func}}($self, $cmdline) };
                }
-               $self->send_ans("Syserr: on stored func $self->{func}", $@) if $@;
+               if ($@) {
+                       $self->send_ans("Syserr: on stored func $self->{func}", $@);
+                       delete $self->{func};
+                       $self->state('prompt');
+                       undef $@;
+               }
                $self->send_ans(@ans);
        } else {
                $self->send_ans(run_cmd($self, $cmdline));
@@ -671,7 +724,7 @@ sub talk
        my ($self, $from, $to, $via, $line) = @_;
        $line =~ s/\\5E/\^/g;
        $self->local_send('T', "$to de $from: $line") if $self->{talk};
-       Log('talk', $to, $from, $main::mycall, $line);
+       Log('talk', $to, $from, $via?$via:$main::mycall, $line);
        # send a 'not here' message if required
        unless ($self->{here} && $from ne $to) {
                my $key = "$to$from";