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
%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+)/ );
$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 {
eval { @ans = &{$self->{func}}($self, $cmdline) };
}
$self->send_ans("Syserr: on stored func $self->{func}", $@) if $@;
+ $self->send_ans(@ans);
} 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;
}
for (keys %Cache) {
undef *{$_};
+ dbg("Undefining cmd $_") if isdbg('command');
}
%cmd_cache = ();
%Cache = ();
# get rid of any existing sub and try to compile the new one
no strict 'refs';
- dbg("[Re]defining $package") if isdbg('command');
- undef *$package;
+ if (exists $Cache{$package}) {
+ dbg("Redefining $package") if isdbg('command');
+ undef *$package;
+ } else {
+ dbg("Defining $package") if isdbg('command');
+ }
eval $eval;
$Cache{$package} = {mtime => $mtime };