added registration
[spider.git] / perl / DXCommandmode.pm
index 3972e8b5b6509ebab966b8aa5303cab3e3cb6e69..3935231bf73fa76f0f7ea617cb8b022a5e424331 100644 (file)
@@ -34,7 +34,7 @@ use Script;
 
 
 use strict;
-use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug);
+use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug $maxbadcount);
 
 %Cache = ();                                   # cache of dynamically loaded routine's mod times
 %cmd_cache = ();                               # cache of short names
@@ -42,6 +42,8 @@ $errstr = ();                                 # error string from eval
 %aliases = ();                                 # aliases for (parts of) commands
 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
 $maxerrors = 20;                               # the maximum number of concurrent errors allowed before disconnection
+$maxbadcount = 3;                              # no of bad words allowed before disconnection
+
 
 use vars qw($VERSION $BRANCH);
 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
@@ -83,12 +85,10 @@ 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} = 80 unless $self->{width} && $self->{width} > 80;
        $self->{consort} = $line;       # save the connection type
@@ -105,6 +105,22 @@ sub start
        $self->{ann_talk} = $user->wantann_talk;
        $self->{here} = 1;
 
+       # sort out registration
+       if ($main::reqreq) {
+               $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);
@@ -121,9 +137,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');
@@ -193,8 +211,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/) {
@@ -205,7 +223,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) {
@@ -220,8 +262,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 {
@@ -241,7 +289,14 @@ sub normal
        } else {
                $self->send_ans(run_cmd($self, $cmdline));
        } 
-       
+
+       # check for excessive swearing
+       if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
+               Log('DXCommand', "$self->{call} logged out for excessive swearing");
+               $self->disconnect;
+               return;
+       }
+
        # send a prompt only if we are in a prompt state
        $self->prompt() if $self->{state} =~ /^prompt/o;
 }