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
58 # obtain a new connection this is derived from dxchannel
63 my $self = DXChannel::alloc(@_);
65 # routing, this must go out here to prevent race condx
68 # my @rout = $main::routeroot->add_user($call, Route::here(1));
69 DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1]);
71 # ALWAYS output the user
72 my $ref = Route::User::get($call);
74 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref);
75 $main::me->route_pc92a($main::mycall, undef, $main::routeroot, $ref) unless $DXProt::pc92_slug_changes;
81 # this is how a a connection starts, you get a hello message and the motd with
82 # possibly some other messages asking you to set various things up if you are
83 # new (or nearly new and slacking) user.
87 my ($self, $line, $sort) = @_;
88 my $user = $self->{user};
89 my $call = $self->{call};
90 my $name = $user->{name};
93 my $host = $self->{conn}->{peerhost};
94 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
96 LogDbg('DXCommand', "$call connected from $host");
98 $self->{name} = $name ? $name : $call;
99 $self->send($self->msg('l2',$self->{name}));
100 $self->state('prompt'); # a bit of room for further expansion, passwords etc
101 $self->{priv} = $user->priv || 0;
102 $self->{lang} = $user->lang || $main::lang || 'en';
103 my $pagelth = $user->pagelth;
104 $pagelth = $default_pagelth unless defined $pagelth;
105 $self->{pagelth} = $pagelth;
106 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
107 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
108 $self->{consort} = $line; # save the connection type
110 # set some necessary flags on the user if they are connecting
111 $self->{beep} = $user->wantbeep;
112 $self->{ann} = $user->wantann;
113 $self->{wwv} = $user->wantwwv;
114 $self->{wcy} = $user->wantwcy;
115 $self->{talk} = $user->wanttalk;
116 $self->{wx} = $user->wantwx;
117 $self->{dx} = $user->wantdx;
118 $self->{logininfo} = $user->wantlogininfo;
119 $self->{ann_talk} = $user->wantann_talk;
121 $self->{prompt} = $user->prompt if $user->prompt;
123 # sort out new dx spot stuff
124 $user->wantdxcq(0) unless defined $user->{wantdxcq};
125 $user->wantdxitu(0) unless defined $user->{wantdxitu};
126 $user->wantusstate(0) unless defined $user->{wantusstate};
128 # sort out registration
129 if ($main::reqreg == 1) {
130 $self->{registered} = $user->registered;
131 } elsif ($main::reqreg == 2) {
132 $self->{registered} = !$user->registered;
134 $self->{registered} = 1;
138 # decide which motd to send
140 unless ($self->{registered}) {
141 $motd = "${main::motd}_nor_$self->{lang}";
142 $motd = "${main::motd}_nor" unless -e $motd;
144 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
145 $motd = $main::motd unless $motd && -e $motd;
146 $self->send_file($motd) if -e $motd;
148 # sort out privilege reduction
149 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
153 $nossid =~ s/-\d+$//;
155 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
156 || Filter::read_in('spots', $nossid, 0)
157 || Filter::read_in('spots', 'user_default', 0);
158 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
159 || Filter::read_in('wwv', $nossid, 0)
160 || Filter::read_in('wwv', 'user_default', 0);
161 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
162 || Filter::read_in('wcy', $nossid, 0)
163 || Filter::read_in('wcy', 'user_default', 0);
164 $self->{annfilter} = Filter::read_in('ann', $call, 0)
165 || Filter::read_in('ann', $nossid, 0)
166 || Filter::read_in('ann', 'user_default', 0) ;
168 # clean up qra locators
169 my $qra = $user->qra;
170 $qra = undef if ($qra && !DXBearing::is_qra($qra));
172 my $lat = $user->lat;
173 my $long = $user->long;
174 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
178 my $echo = $user->wantecho;
180 $self->send_now('E', "0");
181 $self->send($self->msg('echow'));
182 $self->conn->echo($echo) if $self->conn->can('echo');
185 $self->tell_login('loginu');
186 $self->tell_buddies('loginb');
188 # do we need to send a forward/opernam?
189 my $lastoper = $user->lastoper || 0;
190 my $homenode = $user->homenode || "";
191 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
192 run_cmd($main::me, "forward/opernam $call");
193 $user->lastoper($main::systime + ((int rand(10)) * 86400));
196 # run a script send the output to the punter
197 my $script = new Script(lc $call) || new Script('user_default');
198 $script->run($self) if $script;
201 my $info = Route::cluster();
202 $self->send("Cluster:$info");
204 # send prompts for qth, name and things
205 $self->send($self->msg('namee1')) if !$user->name;
206 $self->send($self->msg('qthe1')) if !$user->qth;
207 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
208 $self->send($self->msg('hnodee1')) if !$user->qth;
209 $self->send($self->msg('m9')) if DXMsg::for_me($call);
211 # send out any buddy messages for other people that are online
212 foreach my $call (@{$user->buddies}) {
213 my $ref = Route::User::get($call);
215 foreach my $node (@{$ref->parent}) {
216 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
221 $self->lastmsgpoll($main::systime);
226 # This is the normal command prompt driver
235 # save this for them's that need it
236 my $rawline = $cmdline;
238 # remove leading and trailing spaces
239 $cmdline =~ s/^\s*(.*)\s*$/$1/;
241 if ($self->{state} eq 'page') {
242 my $i = $self->{pagelth};
243 my $ref = $self->{pagedata};
246 # abort if we get a line starting in with a
247 if ($cmdline =~ /^a/io) {
252 # send a tranche of data
253 while ($i-- > 0 && @$ref) {
254 my $line = shift @$ref;
255 $line =~ s/\s+$//o; # why am having to do this?
259 # reset state if none or else chuck out an intermediate prompt
261 $tot -= $self->{pagelth};
262 $self->send($self->msg('page', $tot));
264 $self->state('prompt');
266 } elsif ($self->{state} eq 'sysop') {
267 my $passwd = $self->{user}->passwd;
269 my @pw = grep {$_ !~ /\s/} split //, $passwd;
270 my @l = @{$self->{passwd}};
271 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
272 if ($cmdline =~ /$str/) {
273 $self->{priv} = $self->{user}->priv;
275 $self->send($self->msg('sorry'));
278 $self->send($self->msg('sorry'));
280 $self->state('prompt');
281 } elsif ($self->{state} eq 'passwd') {
282 my $passwd = $self->{user}->passwd;
283 if ($passwd && $cmdline eq $passwd) {
284 $self->send($self->msg('pw1'));
285 $self->state('passwd1');
287 $self->conn->{echo} = $self->conn->{decho};
288 delete $self->conn->{decho};
289 $self->send($self->msg('sorry'));
290 $self->state('prompt');
292 } elsif ($self->{state} eq 'passwd1') {
293 $self->{passwd} = $cmdline;
294 $self->send($self->msg('pw2'));
295 $self->state('passwd2');
296 } elsif ($self->{state} eq 'passwd2') {
297 if ($cmdline eq $self->{passwd}) {
298 $self->{user}->passwd($cmdline);
299 $self->send($self->msg('pw3'));
301 $self->send($self->msg('pw4'));
303 $self->conn->{echo} = $self->conn->{decho};
304 delete $self->conn->{decho};
305 $self->state('prompt');
306 } elsif ($self->{state} eq 'talk' || $self->{state} eq 'chat') {
307 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
308 for (@{$self->{talklist}}) {
309 if ($self->{state} eq 'talk') {
310 $self->send_talks($_, $self->msg('talkend'));
312 $self->local_send('C', $self->msg('chatend', $_));
315 $self->state('prompt');
316 delete $self->{talklist};
317 } elsif ($cmdline =~ m|^/+\w+|) {
319 my $sendit = $cmdline =~ s|^/+||;
320 my @in = $self->run_cmd($cmdline);
321 $self->send_ans(@in);
322 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
323 foreach my $l (@in) {
325 if (@bad = BadWords::check($l)) {
326 $self->badcount(($self->badcount||0) + @bad);
327 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
329 for (@{$self->{talklist}}) {
330 if ($self->{state} eq 'talk') {
331 $self->send_talks($_, $l);
333 send_chats($self, $_, $l)
339 $self->send($self->{state} eq 'talk' ? $self->talk_prompt : $self->chat_prompt);
340 } elsif ($self->{talklist} && @{$self->{talklist}}) {
341 # send what has been said to whoever is in this person's talk list
343 if (@bad = BadWords::check($cmdline)) {
344 $self->badcount(($self->badcount||0) + @bad);
345 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
347 for (@{$self->{talklist}}) {
348 if ($self->{state} eq 'talk') {
349 $self->send_talks($_, $rawline);
351 send_chats($self, $_, $rawline);
355 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
356 $self->send($self->chat_prompt) if $self->{state} eq 'chat';
359 $self->state('prompt');
361 } elsif (my $func = $self->{func}) {
364 if (ref $self->{edit}) {
365 eval { @ans = $self->{edit}->$func($self, $rawline)};
367 eval { @ans = &{$self->{func}}($self, $rawline) };
370 $self->send_ans("Syserr: on stored func $self->{func}", $@);
371 delete $self->{func};
372 $self->state('prompt');
375 $self->send_ans(@ans);
377 $self->send_ans(run_cmd($self, $cmdline));
380 # check for excessive swearing
381 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
382 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
387 # send a prompt only if we are in a prompt state
388 $self->prompt() if $self->{state} =~ /^prompt/o;
391 # send out the talk messages taking into account vias and connectivity
394 my ($self, $ent, $line) = @_;
396 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
397 $to = $ent unless $to;
398 my $call = $via && $via ne '*' ? $via : $to;
399 my $clref = Route::get($call);
400 my $dxchan = $clref->dxchan if $clref;
402 $dxchan->talk($self->{call}, $to, undef, $line);
404 $self->send($self->msg('disc2', $via ? $via : $to));
405 my @l = grep { $_ ne $ent } @{$self->{talklist}};
407 $self->{talklist} = \@l;
409 delete $self->{talklist};
410 $self->state('prompt');
421 my $msgid = DXProt::nextchatmsgid();
422 $text = "#$msgid $text";
423 $main::me->normal(DXProt::pc93($target, $self->{call}, undef, $text));
431 for (@{$self->{talklist}}) {
432 my ($to, $via) = /(\S+)>(\S+)/;
436 return $self->msg($prompt, join(',', @call));
442 return $self->special_prompt('talkprompt');
448 return $self->special_prompt('chatprompt');
452 # send a load of stuff to a command user with page prompting
460 if ($self->{pagelth} && @_ > $self->{pagelth}) {
462 for ($i = $self->{pagelth}; $i-- > 0; ) {
464 $line =~ s/\s+$//o; # why am having to do this?
467 $self->{pagedata} = [ @_ ];
468 $self->state('page');
469 $self->send($self->msg('page', scalar @_));
481 # this is the thing that runs the command, it is done like this for the
482 # benefit of remote command execution
488 my $user = $self->{user};
489 my $call = $self->{call};
494 return () if length $cmdline == 0;
497 # split the command line up into parts, the first part is the command
498 my ($cmd, $args) = split /\s+/, $cmdline, 2;
499 $args = "" unless defined $args;
502 # strip out // on command only
504 $cmd =~ s|^/||g; # no leading / either
505 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
509 dbg("cmd: $cmd") if isdbg('command');
511 # alias it if possible
512 my $acmd = CmdAlias::get_cmd($cmd);
514 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
515 $args = "" unless defined $args;
516 dbg("aliased cmd: $cmd $args") if isdbg('command');
519 # first expand out the entry to a command
520 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
521 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
524 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
526 my $package = find_cmd_name($path, $fcmd);
531 dbg("package: $package") if isdbg('command');
532 eval { @ans = &$package($self, $args) };
533 return (DXDebug::shortmess($@)) if $@;
536 dbg("cmd: $cmd not found") if isdbg('command');
537 if (++$self->{errors} > $maxerrors) {
538 $self->send($self->msg('e26'));
542 return ($self->msg('e1'));
549 delete $self->{errors};
551 if (++$self->{errors} > $maxerrors) {
552 $self->send($self->msg('e26'));
557 return map {s/([^\s])\s+$/$1/; $_} @ans;
561 # This is called from inside the main cluster processing loop and is used
562 # for despatching commands that are doing some long processing job
567 my @dxchan = DXChannel::get_all();
570 foreach $dxchan (@dxchan) {
571 next if $dxchan->sort ne 'U';
573 # send a outstanding message prompt if required
574 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
575 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
576 $dxchan->lastmsgpoll($t);
579 # send a prompt if no activity out on this channel
580 if ($t >= $dxchan->t + $main::user_interval) {
581 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
586 while (my ($k, $v) = each %nothereslug) {
587 if ($main::systime >= $v + 300) {
588 delete $nothereslug{$k};
596 # finish up a user context
601 my $call = $self->call;
603 return if $self->{disconnecting}++;
605 delete $self->{senddbg};
607 my $uref = Route::User::get($call);
610 # @rout = $main::routeroot->del_user($uref);
611 @rout = DXProt::_del_thingy($main::routeroot, [$call, 0]);
613 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
615 # issue a pc17 to everybody interested
616 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
617 $main::me->route_pc92d($main::mycall, undef, $main::routeroot, $uref) unless $DXProt::pc92_slug_changes;
619 confess "trying to disconnect a non existant user $call";
622 # I was the last node visited
623 $self->user->node($main::mycall);
625 # send info to all logged in thingies
626 $self->tell_login('logoutu');
627 $self->tell_buddies('logoutb');
629 LogDbg('DXCommand', "$call disconnected");
631 $self->SUPER::disconnect;
635 # short cut to output a prompt
642 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
644 my $call = $self->call;
645 my $date = cldate($main::systime);
646 my $time = ztime($main::systime);
647 my $prompt = $self->{prompt} || $self->msg('pr');
649 $call = "($call)" unless $self->here;
650 $prompt =~ s/\%C/$call/g;
651 $prompt =~ s/\%D/$date/g;
652 $prompt =~ s/\%T/$time/g;
653 $prompt =~ s/\%M/$main::mycall/g;
655 $self->send($prompt);
658 # broadcast a message to all users [except those mentioned after buffer]
661 my $pkg = shift; # ignored
662 my $s = shift; # the line to be rebroadcast
664 foreach my $dxchan (DXChannel::get_all()) {
665 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
666 next if grep $dxchan == $_, @_;
667 $dxchan->send($s); # send it
671 # gimme all the users
674 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
677 # run a script for this user
681 my $silent = shift || 0;
686 # search for the command in the cache of short->long form commands
691 my ($path, $short_cmd, $suffix) = @_;
694 # commands are lower case
695 $short_cmd = lc $short_cmd;
696 dbg("command: $path $short_cmd\n") if isdbg('command');
698 # do some checking for funny characters
699 return () if $short_cmd =~ /\/$/;
701 # return immediately if we have it
702 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
703 if ($apath && $acmd) {
704 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
705 return ($apath, $acmd);
709 my @parts = split '/', $short_cmd;
713 while (my $p = shift @parts) {
714 opendir(D, $curdir) or confess "can't open $curdir $!";
718 # if this isn't the last part
721 foreach my $l (sort @ls) {
723 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
724 dbg("got dir: $curdir/$l\n") if isdbg('command');
731 # only proceed if we find the directory asked for
732 return () unless $found;
734 foreach my $l (sort @ls) {
736 next unless $l =~ /\.$suffix$/;
737 if ($p eq substr($l, 0, length $p)) {
738 $l =~ s/\.$suffix$//;
739 $dirfn = "" unless $dirfn;
740 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
741 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
742 return ($path, "$dirfn$l");
751 # clear the command name cache
757 undef *{$_} unless /cmd_cache/;
758 dbg("Undefining cmd $_") if isdbg('command');
765 # the persistant execution of things from the command directories
768 # This allows perl programs to call functions dynamically
770 # This has been nicked directly from the perlembed pages
773 #require Devel::Symdump;
775 sub valid_package_name {
777 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
780 return "cmd_$string";
784 # this bit of magic finds a command in the offered directory
788 my $package = valid_package_name($cmdname);
789 my $filename = "$path/$cmdname.pl";
790 my $mtime = -M $filename;
792 # return if we can't find it
794 unless (defined $mtime) {
795 $errstr = DXM::msg('e1');
799 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
800 #we have compiled this subroutine already,
801 #it has not been updated on disk, nothing left to do
802 #print STDERR "already compiled $package->handler\n";
806 my $sub = readfilestr($filename);
808 $errstr = "Syserr: can't open '$filename' $!";
812 #wrap the code into a subroutine inside our unique package
813 my $eval = qq( sub $package { $sub } );
816 my @list = split /\n/, $eval;
819 dbg($_ . "\n") if isdbg('eval');
823 # get rid of any existing sub and try to compile the new one
826 if (exists $Cache{$package}) {
827 dbg("Redefining $package") if isdbg('command');
830 dbg("Defining $package") if isdbg('command');
834 $Cache{$package} = {mtime => $mtime };
846 $self->SUPER::send(dd(['cmd',$_]));
849 $self->SUPER::send(@_);
855 my ($self, $let, $buf) = @_;
856 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk' || $self->{state} eq 'chat') {
857 if ($self->{enhanced}) {
858 $self->send_later($let, $buf);
867 # send a talk message here
870 my ($self, $from, $to, $via, $line, $onode) = @_;
871 $line =~ s/\\5E/\^/g;
874 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
876 $self->local_send('T', "$to de $from: $line");
879 Log('talk', $to, $from, '<' . ($onode || '*'), $line);
880 # send a 'not here' message if required
881 unless ($self->{here} && $from ne $to) {
882 my $key = "$to$from";
883 unless (exists $nothereslug{$key}) {
885 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
886 my $name = $self->user->name || $to;
887 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
888 $nothereslug{$key} = $main::systime;
889 $dxchan->talk($to, $from, undef, $s);
906 if (!$self->{ann_talk} && $to ne $self->{call}) {
907 my $call = AnnTalk::is_talk_candidate($_[0], $text);
911 if ($self->{annfilter}) {
912 ($filter, $hops) = $self->{annfilter}->it(@_ );
913 return unless $filter;
916 unless ($self->{ann}) {
917 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
919 return if $target eq 'SYSOP' && $self->{priv} < 5;
922 $buf = dd(['ann', $to, $target, $text, @_])
924 $buf = "$to$target de $_[0]: $text";
926 $buf .= "\a\a" if $self->{beep};
928 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
942 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
944 $text =~ s/^\#\d+ //;
947 $buf = dd(['chat', $to, $target, $text, @_])
949 $buf = "$target de $_[0]: $text";
951 $buf .= "\a\a" if $self->{beep};
953 $self->local_send('C', $buf);
960 my $t = ztime($_[2]);
962 my $clth = $self->{consort} eq 'local' ? 29 : 30;
963 my $comment = substr (($_[3] || ''), 0, $clth);
964 $comment .= ' ' x ($clth - length($comment));
965 if ($self->{user}->wantgrid) {
966 my $ref = DXUser->get_current($_[4]);
968 $loc = $ref->qra || '';
969 $loc = ' ' . substr($loc, 0, 4) if $loc;
973 if ($self->{user}->wantdxitu) {
974 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
975 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
976 } elsif ($self->{user}->wantdxcq) {
977 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
978 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
979 } elsif ($self->{user}->wantusstate) {
980 $loc = ' ' . $_[13] if $_[13];
981 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
984 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
993 return unless $self->{dx};
997 if ($self->{spotsfilter}) {
998 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
999 return unless $filter;
1002 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
1005 if ($self->{ve7cc}) {
1006 $buf = VE7CC::dx_spot($self, @_);
1007 } elsif ($self->{gtk}) {
1008 my ($dxloc, $byloc);
1010 my $ref = DXUser->get_current($_[4]);
1013 $byloc = substr($byloc, 0, 4) if $byloc;
1017 $spot =~ s|/\w{1,4}$||;
1018 $ref = DXUser->get_current($spot);
1021 $dxloc = substr($dxloc, 0, 4) if $dxloc;
1023 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
1026 $buf = $self->format_dx_spot(@_);
1027 $buf .= "\a\a" if $self->{beep};
1031 $self->local_send('X', $buf);
1038 my $isolate = shift;
1039 my ($filter, $hops);
1041 return unless $self->{wwv};
1043 if ($self->{wwvfilter}) {
1044 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1045 return unless $filter;
1050 $buf = dd(['wwv', @_])
1052 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1053 $buf .= "\a\a" if $self->{beep};
1056 $self->local_send('V', $buf);
1063 my $isolate = shift;
1064 my ($filter, $hops);
1066 return unless $self->{wcy};
1068 if ($self->{wcyfilter}) {
1069 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1070 return unless $filter;
1075 $buf = dd(['wcy', @_])
1077 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1078 $buf .= "\a\a" if $self->{beep};
1080 $self->local_send('Y', $buf);
1083 # broadcast debug stuff to all interested parties
1086 my $s = shift; # the line to be rebroadcast
1088 foreach my $dxchan (DXChannel::get_all) {
1089 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1090 if ($dxchan->{gtk}) {
1091 $dxchan->send_later('L', dd(['db', $s]));
1093 $dxchan->send_later('L', $s);
1104 if ($self->state eq 'enterbody') {
1105 my $loc = $self->{loc} || confess "local var gone missing" ;
1106 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1108 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1110 $self->state('prompt');
1111 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1112 push @out, $self->msg('m10');
1113 delete $loc->{lines};
1114 delete $self->{loc};
1116 $self->state('prompt');
1118 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1119 # i.e. it ain't and end or abort, therefore store the line
1122 confess "Invalid state $self->{state}";
1127 sub store_startup_script
1130 my $loc = $self->{loc} || confess "local var gone missing" ;
1132 my $call = $loc->{call} || confess "callsign gone missing";
1133 confess "lines array gone missing" unless ref $loc->{lines};
1134 my $r = Script::store($call, $loc->{lines});
1137 push @out, $self->msg('m19', $call, $r);
1139 push @out, $self->msg('m20', $call);
1142 push @out, "error opening startup script $call $!";
1147 # Import any commands contained in any files in import_cmd directory
1149 # If the filename has a recogisable callsign as some delimited part
1150 # of it, then this is the user the command will be run as.
1154 # are there any to do in this directory?
1155 return unless -d $cmdimportdir;
1156 unless (opendir(DIR, $cmdimportdir)) {
1157 LogDbg('err', "can\'t open $cmdimportdir $!");
1161 my @names = readdir(DIR);
1164 foreach $name (@names) {
1165 next if $name =~ /^\./;
1167 my $s = Script->new($name, $cmdimportdir);
1169 LogDbg('DXCommand', "Run import cmd file $name");
1170 my @cat = split /[^A-Za-z0-9]+/, $name;
1171 my ($call) = grep {is_callsign(uc $_)} @cat;
1172 $call ||= $main::mycall;
1177 $s->inscript(0); # switch off script checks
1179 if ($call eq $main::mycall) {
1180 @out = $s->run($main::me, 1);
1182 my $dxchan = DXChannel::get($call);
1184 @out = $s->run($dxchan, 1);
1186 my $u = DXUser->get($call);
1188 $dxchan = $main::me;
1189 my $old = $dxchan->{call};
1190 my $priv = $dxchan->{priv};
1191 my $user = $dxchan->{user};
1192 $dxchan->{call} = $call;
1193 $dxchan->{priv} = $u->priv;
1194 $dxchan->{user} = $u;
1195 @out = $s->run($dxchan, 1);
1196 $dxchan->{call} = $call;
1197 $dxchan->{priv} = $priv;
1198 $dxchan->{user} = $user;
1200 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1206 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1209 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1210 unlink "$cmdimportdir/$name";
1215 sub print_find_reply
1217 my ($self, $node, $target, $flag, $ms) = @_;
1218 my $sort = $flag == 2 ? "External" : "Local";
1219 $self->send("$sort $target found at $node in $ms ms" );