3 # This module impliments the user facing command mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
10 package DXCommandmode;
16 use POSIX qw(:math_h);
42 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug
43 $maxbadcount $msgpolltime $default_pagelth $cmdimportdir);
45 %Cache = (); # cache of dynamically loaded routine's mod times
46 %cmd_cache = (); # cache of short names
47 $errstr = (); # error string from eval
48 %aliases = (); # aliases for (parts of) commands
49 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
50 $maxerrors = 20; # the maximum number of concurrent errors allowed before disconnection
51 $maxbadcount = 3; # no of bad words allowed before disconnection
52 $msgpolltime = 3600; # the time between polls for new messages
53 $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts
54 # this does not exist as default, you need to create it manually
57 use vars qw($VERSION $BRANCH);
58 ($VERSION, $BRANCH) = dxver(q$Revision$);
61 # obtain a new connection this is derived from dxchannel
66 my $self = DXChannel::alloc(@_);
68 # routing, this must go out here to prevent race condx
71 my @rout = $main::routeroot->add_user($call, Route::here(1));
73 # ALWAYS output the user
74 my $ref = Route::User::get($call);
76 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref);
77 $main::me->route_pc92a($main::mycall, undef, $main::routeroot, $ref);
83 # this is how a a connection starts, you get a hello message and the motd with
84 # possibly some other messages asking you to set various things up if you are
85 # new (or nearly new and slacking) user.
89 my ($self, $line, $sort) = @_;
90 my $user = $self->{user};
91 my $call = $self->{call};
92 my $name = $user->{name};
95 my $host = $self->{conn}->{peerhost};
96 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
98 LogDbg('DXCommand', "$call connected from $host");
100 $self->{name} = $name ? $name : $call;
101 $self->send($self->msg('l2',$self->{name}));
102 $self->state('prompt'); # a bit of room for further expansion, passwords etc
103 $self->{priv} = $user->priv || 0;
104 $self->{lang} = $user->lang || $main::lang || 'en';
105 my $pagelth = $user->pagelth;
106 $pagelth = $default_pagelth unless defined $pagelth;
107 $self->{pagelth} = $pagelth;
108 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
109 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
110 $self->{consort} = $line; # save the connection type
112 # set some necessary flags on the user if they are connecting
113 $self->{beep} = $user->wantbeep;
114 $self->{ann} = $user->wantann;
115 $self->{wwv} = $user->wantwwv;
116 $self->{wcy} = $user->wantwcy;
117 $self->{talk} = $user->wanttalk;
118 $self->{wx} = $user->wantwx;
119 $self->{dx} = $user->wantdx;
120 $self->{logininfo} = $user->wantlogininfo;
121 $self->{ann_talk} = $user->wantann_talk;
123 $self->{prompt} = $user->prompt if $user->prompt;
125 # sort out new dx spot stuff
126 $user->wantdxcq(0) unless defined $user->{wantdxcq};
127 $user->wantdxitu(0) unless defined $user->{wantdxitu};
128 $user->wantusstate(0) unless defined $user->{wantusstate};
130 # sort out registration
131 if ($main::reqreg == 1) {
132 $self->{registered} = $user->registered;
133 } elsif ($main::reqreg == 2) {
134 $self->{registered} = !$user->registered;
136 $self->{registered} = 1;
140 # decide which motd to send
142 unless ($self->{registered}) {
143 $motd = "${main::motd}_nor_$self->{lang}";
144 $motd = "${main::motd}_nor" unless -e $motd;
146 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
147 $motd = $main::motd unless $motd && -e $motd;
148 $self->send_file($motd) if -e $motd;
150 # sort out privilege reduction
151 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
155 $nossid =~ s/-\d+$//;
157 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
158 || Filter::read_in('spots', $nossid, 0)
159 || Filter::read_in('spots', 'user_default', 0);
160 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
161 || Filter::read_in('wwv', $nossid, 0)
162 || Filter::read_in('wwv', 'user_default', 0);
163 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
164 || Filter::read_in('wcy', $nossid, 0)
165 || Filter::read_in('wcy', 'user_default', 0);
166 $self->{annfilter} = Filter::read_in('ann', $call, 0)
167 || Filter::read_in('ann', $nossid, 0)
168 || Filter::read_in('ann', 'user_default', 0) ;
170 # clean up qra locators
171 my $qra = $user->qra;
172 $qra = undef if ($qra && !DXBearing::is_qra($qra));
174 my $lat = $user->lat;
175 my $long = $user->long;
176 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
180 my $echo = $user->wantecho;
182 $self->send_now('E', "0");
183 $self->send($self->msg('echow'));
184 $self->conn->echo($echo) if $self->conn->can('echo');
187 $self->tell_login('loginu');
188 $self->tell_buddies('loginb');
190 # do we need to send a forward/opernam?
191 my $lastoper = $user->lastoper || 0;
192 my $homenode = $user->homenode || "";
193 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
194 run_cmd($main::me, "forward/opernam $call");
195 $user->lastoper($main::systime + ((int rand(10)) * 86400));
198 # run a script send the output to the punter
199 my $script = new Script(lc $call) || new Script('user_default');
200 $script->run($self) if $script;
203 my $info = Route::cluster();
204 $self->send("Cluster:$info");
206 # send prompts for qth, name and things
207 $self->send($self->msg('namee1')) if !$user->name;
208 $self->send($self->msg('qthe1')) if !$user->qth;
209 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
210 $self->send($self->msg('hnodee1')) if !$user->qth;
211 $self->send($self->msg('m9')) if DXMsg::for_me($call);
213 # send out any buddy messages for other people that are online
214 foreach my $call (@{$user->buddies}) {
215 my $ref = Route::User::get($call);
217 foreach my $node (@{$ref->parent}) {
218 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
223 $self->lastmsgpoll($main::systime);
228 # This is the normal command prompt driver
237 # save this for them's that need it
238 my $rawline = $cmdline;
240 # remove leading and trailing spaces
241 $cmdline =~ s/^\s*(.*)\s*$/$1/;
243 if ($self->{state} eq 'page') {
244 my $i = $self->{pagelth};
245 my $ref = $self->{pagedata};
248 # abort if we get a line starting in with a
249 if ($cmdline =~ /^a/io) {
254 # send a tranche of data
255 while ($i-- > 0 && @$ref) {
256 my $line = shift @$ref;
257 $line =~ s/\s+$//o; # why am having to do this?
261 # reset state if none or else chuck out an intermediate prompt
263 $tot -= $self->{pagelth};
264 $self->send($self->msg('page', $tot));
266 $self->state('prompt');
268 } elsif ($self->{state} eq 'sysop') {
269 my $passwd = $self->{user}->passwd;
271 my @pw = grep {$_ !~ /\s/} split //, $passwd;
272 my @l = @{$self->{passwd}};
273 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
274 if ($cmdline =~ /$str/) {
275 $self->{priv} = $self->{user}->priv;
277 $self->send($self->msg('sorry'));
280 $self->send($self->msg('sorry'));
282 $self->state('prompt');
283 } elsif ($self->{state} eq 'passwd') {
284 my $passwd = $self->{user}->passwd;
285 if ($passwd && $cmdline eq $passwd) {
286 $self->send($self->msg('pw1'));
287 $self->state('passwd1');
289 $self->conn->{echo} = $self->conn->{decho};
290 delete $self->conn->{decho};
291 $self->send($self->msg('sorry'));
292 $self->state('prompt');
294 } elsif ($self->{state} eq 'passwd1') {
295 $self->{passwd} = $cmdline;
296 $self->send($self->msg('pw2'));
297 $self->state('passwd2');
298 } elsif ($self->{state} eq 'passwd2') {
299 if ($cmdline eq $self->{passwd}) {
300 $self->{user}->passwd($cmdline);
301 $self->send($self->msg('pw3'));
303 $self->send($self->msg('pw4'));
305 $self->conn->{echo} = $self->conn->{decho};
306 delete $self->conn->{decho};
307 $self->state('prompt');
308 } elsif ($self->{state} eq 'talk') {
309 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
310 for (@{$self->{talklist}}) {
311 $self->send_talks($_, $self->msg('talkend'));
313 $self->state('prompt');
314 delete $self->{talklist};
315 } elsif ($cmdline =~ m|^/+\w+|) {
317 my $sendit = $cmdline =~ s|^/+||;
318 my @in = $self->run_cmd($cmdline);
319 $self->send_ans(@in);
320 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
321 foreach my $l (@in) {
323 if (@bad = BadWords::check($l)) {
324 $self->badcount(($self->badcount||0) + @bad);
325 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
327 for (@{$self->{talklist}}) {
328 $self->send_talks($_, $l);
333 $self->send($self->talk_prompt);
334 } elsif ($self->{talklist} && @{$self->{talklist}}) {
335 # send what has been said to whoever is in this person's talk list
337 if (@bad = BadWords::check($cmdline)) {
338 $self->badcount(($self->badcount||0) + @bad);
339 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
341 for (@{$self->{talklist}}) {
342 $self->send_talks($_, $rawline);
345 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
348 $self->state('prompt');
350 } elsif (my $func = $self->{func}) {
353 if (ref $self->{edit}) {
354 eval { @ans = $self->{edit}->$func($self, $rawline)};
356 eval { @ans = &{$self->{func}}($self, $rawline) };
359 $self->send_ans("Syserr: on stored func $self->{func}", $@);
360 delete $self->{func};
361 $self->state('prompt');
364 $self->send_ans(@ans);
366 $self->send_ans(run_cmd($self, $cmdline));
369 # check for excessive swearing
370 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
371 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
376 # send a prompt only if we are in a prompt state
377 $self->prompt() if $self->{state} =~ /^prompt/o;
380 # send out the talk messages taking into account vias and connectivity
383 my ($self, $ent, $line) = @_;
385 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
386 $to = $ent unless $to;
387 my $call = $via ? $via : $to;
388 my $clref = Route::get($call);
389 my $dxchan = $clref->dxchan if $clref;
391 $dxchan->talk($self->{call}, $to, $via, $line);
393 $self->send($self->msg('disc2', $via ? $via : $to));
394 my @l = grep { $_ ne $ent } @{$self->{talklist}};
396 $self->{talklist} = \@l;
398 delete $self->{talklist};
399 $self->state('prompt');
408 for (@{$self->{talklist}}) {
409 my ($to, $via) = /(\S+)>(\S+)/;
413 return $self->msg('talkprompt', join(',', @call));
417 # send a load of stuff to a command user with page prompting
425 if ($self->{pagelth} && @_ > $self->{pagelth}) {
427 for ($i = $self->{pagelth}; $i-- > 0; ) {
429 $line =~ s/\s+$//o; # why am having to do this?
432 $self->{pagedata} = [ @_ ];
433 $self->state('page');
434 $self->send($self->msg('page', scalar @_));
446 # this is the thing that runs the command, it is done like this for the
447 # benefit of remote command execution
453 my $user = $self->{user};
454 my $call = $self->{call};
459 return () if length $cmdline == 0;
462 # split the command line up into parts, the first part is the command
463 my ($cmd, $args) = split /\s+/, $cmdline, 2;
464 $args = "" unless defined $args;
467 # strip out // on command only
469 $cmd =~ s|^/||g; # no leading / either
470 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
474 dbg("cmd: $cmd") if isdbg('command');
476 # alias it if possible
477 my $acmd = CmdAlias::get_cmd($cmd);
479 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
480 $args = "" unless defined $args;
481 dbg("aliased cmd: $cmd $args") if isdbg('command');
484 # first expand out the entry to a command
485 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
486 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
489 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
491 my $package = find_cmd_name($path, $fcmd);
496 dbg("package: $package") if isdbg('command');
497 eval { @ans = &$package($self, $args) };
498 return (DXDebug::shortmess($@)) if $@;
501 dbg("cmd: $cmd not found") if isdbg('command');
502 if (++$self->{errors} > $maxerrors) {
503 $self->send($self->msg('e26'));
507 return ($self->msg('e1'));
514 delete $self->{errors};
516 if (++$self->{errors} > $maxerrors) {
517 $self->send($self->msg('e26'));
522 return map {s/([^\s])\s+$/$1/; $_} @ans;
526 # This is called from inside the main cluster processing loop and is used
527 # for despatching commands that are doing some long processing job
532 my @dxchan = DXChannel::get_all();
535 foreach $dxchan (@dxchan) {
536 next if $dxchan->sort ne 'U';
538 # send a outstanding message prompt if required
539 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
540 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
541 $dxchan->lastmsgpoll($t);
544 # send a prompt if no activity out on this channel
545 if ($t >= $dxchan->t + $main::user_interval) {
546 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
551 while (my ($k, $v) = each %nothereslug) {
552 if ($main::systime >= $v + 300) {
553 delete $nothereslug{$k};
561 # finish up a user context
566 my $call = $self->call;
568 return if $self->{disconnecting}++;
570 delete $self->{senddbg};
572 my $uref = Route::User::get($call);
575 @rout = $main::routeroot->del_user($uref);
576 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
578 # issue a pc17 to everybody interested
579 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
580 $main::me->route_pc92d($main::mycall, undef, $main::routeroot, $uref);
582 confess "trying to disconnect a non existant user $call";
585 # I was the last node visited
586 $self->user->node($main::mycall);
588 # send info to all logged in thingies
589 $self->tell_login('logoutu');
590 $self->tell_buddies('logoutb');
592 LogDbg('DXCommand', "$call disconnected");
594 $self->SUPER::disconnect;
598 # short cut to output a prompt
605 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
607 my $call = $self->call;
608 my $date = cldate($main::systime);
609 my $time = ztime($main::systime);
610 my $prompt = $self->{prompt} || $self->msg('pr');
612 $call = "($call)" unless $self->here;
613 $prompt =~ s/\%C/$call/g;
614 $prompt =~ s/\%D/$date/g;
615 $prompt =~ s/\%T/$time/g;
616 $prompt =~ s/\%M/$main::mycall/g;
618 $self->send($prompt);
621 # broadcast a message to all users [except those mentioned after buffer]
624 my $pkg = shift; # ignored
625 my $s = shift; # the line to be rebroadcast
627 foreach my $dxchan (DXChannel::get_all()) {
628 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
629 next if grep $dxchan == $_, @_;
630 $dxchan->send($s); # send it
634 # gimme all the users
637 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
640 # run a script for this user
644 my $silent = shift || 0;
649 # search for the command in the cache of short->long form commands
654 my ($path, $short_cmd, $suffix) = @_;
657 # commands are lower case
658 $short_cmd = lc $short_cmd;
659 dbg("command: $path $short_cmd\n") if isdbg('command');
661 # do some checking for funny characters
662 return () if $short_cmd =~ /\/$/;
664 # return immediately if we have it
665 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
666 if ($apath && $acmd) {
667 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
668 return ($apath, $acmd);
672 my @parts = split '/', $short_cmd;
676 while (my $p = shift @parts) {
677 opendir(D, $curdir) or confess "can't open $curdir $!";
681 # if this isn't the last part
684 foreach my $l (sort @ls) {
686 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
687 dbg("got dir: $curdir/$l\n") if isdbg('command');
694 # only proceed if we find the directory asked for
695 return () unless $found;
697 foreach my $l (sort @ls) {
699 next unless $l =~ /\.$suffix$/;
700 if ($p eq substr($l, 0, length $p)) {
701 $l =~ s/\.$suffix$//;
702 $dirfn = "" unless $dirfn;
703 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
704 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
705 return ($path, "$dirfn$l");
714 # clear the command name cache
720 undef *{$_} unless /cmd_cache/;
721 dbg("Undefining cmd $_") if isdbg('command');
728 # the persistant execution of things from the command directories
731 # This allows perl programs to call functions dynamically
733 # This has been nicked directly from the perlembed pages
736 #require Devel::Symdump;
738 sub valid_package_name {
740 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
743 return "cmd_$string";
747 # this bit of magic finds a command in the offered directory
751 my $package = valid_package_name($cmdname);
752 my $filename = "$path/$cmdname.pl";
753 my $mtime = -M $filename;
755 # return if we can't find it
757 unless (defined $mtime) {
758 $errstr = DXM::msg('e1');
762 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
763 #we have compiled this subroutine already,
764 #it has not been updated on disk, nothing left to do
765 #print STDERR "already compiled $package->handler\n";
769 my $sub = readfilestr($filename);
771 $errstr = "Syserr: can't open '$filename' $!";
775 #wrap the code into a subroutine inside our unique package
776 my $eval = qq( sub $package { $sub } );
779 my @list = split /\n/, $eval;
782 dbg($_ . "\n") if isdbg('eval');
786 # get rid of any existing sub and try to compile the new one
789 if (exists $Cache{$package}) {
790 dbg("Redefining $package") if isdbg('command');
793 dbg("Defining $package") if isdbg('command');
797 $Cache{$package} = {mtime => $mtime };
809 $self->SUPER::send(dd(['cmd',$_]));
812 $self->SUPER::send(@_);
818 my ($self, $let, $buf) = @_;
819 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
820 if ($self->{enhanced}) {
821 $self->send_later($let, $buf);
830 # send a talk message here
833 my ($self, $from, $to, $via, $line) = @_;
834 $line =~ s/\\5E/\^/g;
837 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
839 $self->local_send('T', "$to de $from: $line");
842 Log('talk', $to, $from, $via?$via:$main::mycall, $line);
843 # send a 'not here' message if required
844 unless ($self->{here} && $from ne $to) {
845 my $key = "$to$from";
846 unless (exists $nothereslug{$key}) {
848 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
849 my $name = $self->user->name || $to;
850 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
851 $nothereslug{$key} = $main::systime;
852 $dxchan->talk($to, $from, undef, $s);
869 if (!$self->{ann_talk} && $to ne $self->{call}) {
870 my $call = AnnTalk::is_talk_candidate($_[0], $text);
874 if ($self->{annfilter}) {
875 ($filter, $hops) = $self->{annfilter}->it(@_ );
876 return unless $filter;
879 unless ($self->{ann}) {
880 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
882 return if $target eq 'SYSOP' && $self->{priv} < 5;
885 $buf = dd(['ann', $to, $target, $text, @_])
887 $buf = "$to$target de $_[0]: $text";
889 $buf .= "\a\a" if $self->{beep};
891 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
905 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
907 $text =~ s/^\#\d+ //;
910 $buf = dd(['chat', $to, $target, $text, @_])
912 $buf = "$target de $_[0]: $text";
914 $buf .= "\a\a" if $self->{beep};
916 $self->local_send('C', $buf);
923 my $t = ztime($_[2]);
925 my $clth = $self->{consort} eq 'local' ? 29 : 30;
926 my $comment = substr $_[3], 0, $clth;
927 $comment .= ' ' x ($clth - length($comment));
928 if ($self->{user}->wantgrid) {
929 my $ref = DXUser->get_current($_[4]);
931 $loc = $ref->qra || '';
932 $loc = ' ' . substr($loc, 0, 4) if $loc;
936 if ($self->{user}->wantdxitu) {
937 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
938 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
939 } elsif ($self->{user}->wantdxcq) {
940 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
941 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
942 } elsif ($self->{user}->wantusstate) {
943 $loc = ' ' . $_[13] if $_[13];
944 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
947 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
956 return unless $self->{dx};
960 if ($self->{spotsfilter}) {
961 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
962 return unless $filter;
965 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
968 if ($self->{ve7cc}) {
969 $buf = VE7CC::dx_spot($self, @_);
970 } elsif ($self->{gtk}) {
973 my $ref = DXUser->get_current($_[4]);
976 $byloc = substr($byloc, 0, 4) if $byloc;
980 $spot =~ s|/\w{1,4}$||;
981 $ref = DXUser->get_current($spot);
984 $dxloc = substr($dxloc, 0, 4) if $dxloc;
986 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
989 $buf = $self->format_dx_spot(@_);
990 $buf .= "\a\a" if $self->{beep};
994 $self->local_send('X', $buf);
1001 my $isolate = shift;
1002 my ($filter, $hops);
1004 return unless $self->{wwv};
1006 if ($self->{wwvfilter}) {
1007 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1008 return unless $filter;
1013 $buf = dd(['wwv', @_])
1015 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1016 $buf .= "\a\a" if $self->{beep};
1019 $self->local_send('V', $buf);
1026 my $isolate = shift;
1027 my ($filter, $hops);
1029 return unless $self->{wcy};
1031 if ($self->{wcyfilter}) {
1032 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1033 return unless $filter;
1038 $buf = dd(['wcy', @_])
1040 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1041 $buf .= "\a\a" if $self->{beep};
1043 $self->local_send('Y', $buf);
1046 # broadcast debug stuff to all interested parties
1049 my $s = shift; # the line to be rebroadcast
1051 foreach my $dxchan (DXChannel::get_all) {
1052 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1053 if ($dxchan->{gtk}) {
1054 $dxchan->send_later('L', dd(['db', $s]));
1056 $dxchan->send_later('L', $s);
1067 if ($self->state eq 'enterbody') {
1068 my $loc = $self->{loc} || confess "local var gone missing" ;
1069 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1071 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1073 $self->state('prompt');
1074 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1075 push @out, $self->msg('m10');
1076 delete $loc->{lines};
1077 delete $self->{loc};
1079 $self->state('prompt');
1081 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1082 # i.e. it ain't and end or abort, therefore store the line
1085 confess "Invalid state $self->{state}";
1090 sub store_startup_script
1093 my $loc = $self->{loc} || confess "local var gone missing" ;
1095 my $call = $loc->{call} || confess "callsign gone missing";
1096 confess "lines array gone missing" unless ref $loc->{lines};
1097 my $r = Script::store($call, $loc->{lines});
1100 push @out, $self->msg('m19', $call, $r);
1102 push @out, $self->msg('m20', $call);
1105 push @out, "error opening startup script $call $!";
1110 # Import any commands contained in any files in import_cmd directory
1112 # If the filename has a recogisable callsign as some delimited part
1113 # of it, then this is the user the command will be run as.
1117 # are there any to do in this directory?
1118 return unless -d $cmdimportdir;
1119 unless (opendir(DIR, $cmdimportdir)) {
1120 LogDbg('err', "can\'t open $cmdimportdir $!");
1124 my @names = readdir(DIR);
1127 foreach $name (@names) {
1128 next if $name =~ /^\./;
1130 my $s = Script->new($name, $cmdimportdir);
1132 LogDbg('DXCommand', "Run import cmd file $name");
1133 my @cat = split /[^A-Za-z0-9]+/, $name;
1134 my ($call) = grep {is_callsign(uc $_)} @cat;
1135 $call ||= $main::mycall;
1140 $s->inscript(0); # switch off script checks
1142 if ($call eq $main::mycall) {
1143 @out = $s->run($main::me, 1);
1145 my $dxchan = DXChannel::get($call);
1147 @out = $s->run($dxchan, 1);
1149 my $u = DXUser->get($call);
1151 $dxchan = $main::me;
1152 my $old = $dxchan->{call};
1153 my $priv = $dxchan->{priv};
1154 my $user = $dxchan->{user};
1155 $dxchan->{call} = $call;
1156 $dxchan->{priv} = $u->priv;
1157 $dxchan->{user} = $u;
1158 @out = $s->run($dxchan, 1);
1159 $dxchan->{call} = $call;
1160 $dxchan->{priv} = $priv;
1161 $dxchan->{user} = $user;
1163 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1169 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1172 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1173 unlink "$cmdimportdir/$name";
1178 sub print_find_reply
1180 my ($self, $node, $target, $flag, $ms) = @_;
1181 my $sort = $flag == 2 ? "External" : "Local";
1182 $self->send("$sort $target found at $node in $ms ms" );