+}
+
+sub talk_prompt
+{
+ my $self = shift;
+ my @call;
+ for (@{$self->{talklist}}) {
+ my ($to, $via) = /(\S+)>(\S+)/;
+ $to = $_ unless $to;
+ push @call, $to;
+ }
+ return $self->msg('talkprompt', join(',', @call));
+}
+
+#
+# send a load of stuff to a command user with page prompting
+# and stuff
+#
+
+sub send_ans
+{
+ my $self = shift;
+
+ if ($self->{pagelth} && @_ > $self->{pagelth}) {
+ my $i;
+ for ($i = $self->{pagelth}; $i-- > 0; ) {
+ my $line = shift @_;
+ $line =~ s/\s+$//o; # why am having to do this?
+ $self->send($line);
+ }
+ $self->{pagedata} = [ @_ ];
+ $self->state('page');
+ $self->send($self->msg('page', scalar @_));
+ } else {
+ for (@_) {
+ if (defined $_) {
+ $self->send($_);
+ } else {
+ $self->send('');
+ }
+ }
+ }
+}
+#
+# this is the thing that runs the command, it is done like this for the
+# benefit of remote command execution
+#
+
+sub run_cmd
+{
+ my $self = shift;
+ my $user = $self->{user};
+ my $call = $self->{call};
+ my $cmdline = shift;
+ my @ans;
+
+ if ($self->{func}) {
+ my $c = qq{ \@ans = $self->{func}(\$self, \$cmdline) };
+ dbg("stored func cmd = $c\n") if isdbg('eval');
+ eval $c;
+ if ($@) {
+ return ("Syserr: Eval err $errstr on stored func $self->{func}", $@);
+ }
+ } else {
+
+ return () if length $cmdline == 0;
+
+ # strip out //
+ $cmdline =~ s|//|/|og;
+
+ # split the command line up into parts, the first part is the command
+ my ($cmd, $args) = split /\s+/, $cmdline, 2;
+ $args = "" unless defined $args;
+
+ if ($cmd) {
+
+ my ($path, $fcmd);
+
+ dbg("cmd: $cmd") if isdbg('command');
+
+ # alias it if possible
+ my $acmd = CmdAlias::get_cmd($cmd);
+ if ($acmd) {
+ ($cmd, $args) = split /\s+/, "$acmd $args", 2;
+ $args = "" unless defined $args;
+ dbg("aliased cmd: $cmd $args") if isdbg('command');
+ }
+
+ # first expand out the entry to a command
+ ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
+ ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
+
+ if ($path && $cmd) {
+ dbg("path: $cmd cmd: $fcmd") if isdbg('command');
+
+ my $package = find_cmd_name($path, $fcmd);
+ @ans = (0) if !$package ;
+
+ if ($package) {
+ dbg("package: $package") if isdbg('command');
+ my $c;
+ unless (exists $Cache{$package}->{'sub'}) {
+ $c = eval $Cache{$package}->{'eval'};
+ if ($@) {
+ return DXDebug::shortmess($@);
+ }
+ $Cache{$package}->{'sub'} = $c;
+ }
+ $c = $Cache{$package}->{'sub'};
+ eval {
+ @ans = &{$c}($self, $args);
+ };
+
+ if ($@) {
+ #cluck($@);
+ return (DXDebug::shortmess($@));
+ };
+ }
+ } else {
+ dbg("cmd: $cmd not found") if isdbg('command');
+ if (++$self->{errors} > $maxerrors) {
+ $self->send($self->msg('e26'));
+ $self->disconnect;
+ return ();
+ } else {
+ return ($self->msg('e1'));
+ }
+ }
+ }
+ }
+
+ my $ok = shift @ans;
+ if ($ok) {
+ delete $self->{errors};
+ } else {
+ if (++$self->{errors} > $maxerrors) {
+ $self->send($self->msg('e26'));
+ $self->disconnect;
+ return ();
+ }
+ }
+ return (@ans);