add an error counter to stop runaway spot suckers
[spider.git] / perl / DXCommandmode.pm
index 6e7a0944f5461c109d9b4a5d6a5106ba2092515b..967cc022d10cbefb04fb0dcf68902c6ee5ffeeb3 100644 (file)
@@ -32,13 +32,14 @@ use Sun;
 use Internet;
 
 use strict;
-use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase);
+use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors);
 
 %Cache = ();                                   # cache of dynamically loaded routine's mod times
 %cmd_cache = ();                               # cache of short names
 $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
 
 #
 # obtain a new connection this is derived from dxchannel
@@ -351,12 +352,27 @@ sub run_cmd
                                }
                        } else {
                                dbg('command', "cmd: $cmd not found");
-                               return ($self->msg('e1'));
+                               if (++$self->{errors} > $maxerrors) {
+                                       $self->send($self->msg('e26'));
+                                       $self->disconnect;
+                                       return ();
+                               } else {
+                                       return ($self->msg('e1'));
+                               }
                        }
                }
        }
        
-       shift @ans;
+       my $ok = shift @ans;
+       if ($ok) {
+               delete $self->{errors};
+       } else {
+               if (++$self->{errors} > $maxerrors) {
+                       $self->send($self->msg('e26'));
+                       $self->disconnect;
+                       return ();
+               }
+       }
        return (@ans);
 }