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));
70 # ALWAYS output the user
71 my $ref = Route::User::get($call);
73 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref);
74 $main::me->route_pc92a($main::mycall, undef, $main::routeroot, $ref);
80 # this is how a a connection starts, you get a hello message and the motd with
81 # possibly some other messages asking you to set various things up if you are
82 # new (or nearly new and slacking) user.
86 my ($self, $line, $sort) = @_;
87 my $user = $self->{user};
88 my $call = $self->{call};
89 my $name = $user->{name};
92 my $host = $self->{conn}->{peerhost};
93 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
95 LogDbg('DXCommand', "$call connected from $host");
97 $self->{name} = $name ? $name : $call;
98 $self->send($self->msg('l2',$self->{name}));
99 $self->state('prompt'); # a bit of room for further expansion, passwords etc
100 $self->{priv} = $user->priv || 0;
101 $self->{lang} = $user->lang || $main::lang || 'en';
102 my $pagelth = $user->pagelth;
103 $pagelth = $default_pagelth unless defined $pagelth;
104 $self->{pagelth} = $pagelth;
105 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
106 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
107 $self->{consort} = $line; # save the connection type
109 # set some necessary flags on the user if they are connecting
110 $self->{beep} = $user->wantbeep;
111 $self->{ann} = $user->wantann;
112 $self->{wwv} = $user->wantwwv;
113 $self->{wcy} = $user->wantwcy;
114 $self->{talk} = $user->wanttalk;
115 $self->{wx} = $user->wantwx;
116 $self->{dx} = $user->wantdx;
117 $self->{logininfo} = $user->wantlogininfo;
118 $self->{ann_talk} = $user->wantann_talk;
120 $self->{prompt} = $user->prompt if $user->prompt;
122 # sort out new dx spot stuff
123 $user->wantdxcq(0) unless defined $user->{wantdxcq};
124 $user->wantdxitu(0) unless defined $user->{wantdxitu};
125 $user->wantusstate(0) unless defined $user->{wantusstate};
127 # sort out registration
128 if ($main::reqreg == 1) {
129 $self->{registered} = $user->registered;
130 } elsif ($main::reqreg == 2) {
131 $self->{registered} = !$user->registered;
133 $self->{registered} = 1;
137 # decide which motd to send
139 unless ($self->{registered}) {
140 $motd = "${main::motd}_nor_$self->{lang}";
141 $motd = "${main::motd}_nor" unless -e $motd;
143 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
144 $motd = $main::motd unless $motd && -e $motd;
145 $self->send_file($motd) if -e $motd;
147 # sort out privilege reduction
148 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
152 $nossid =~ s/-\d+$//;
154 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
155 || Filter::read_in('spots', $nossid, 0)
156 || Filter::read_in('spots', 'user_default', 0);
157 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
158 || Filter::read_in('wwv', $nossid, 0)
159 || Filter::read_in('wwv', 'user_default', 0);
160 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
161 || Filter::read_in('wcy', $nossid, 0)
162 || Filter::read_in('wcy', 'user_default', 0);
163 $self->{annfilter} = Filter::read_in('ann', $call, 0)
164 || Filter::read_in('ann', $nossid, 0)
165 || Filter::read_in('ann', 'user_default', 0) ;
167 # clean up qra locators
168 my $qra = $user->qra;
169 $qra = undef if ($qra && !DXBearing::is_qra($qra));
171 my $lat = $user->lat;
172 my $long = $user->long;
173 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
177 my $echo = $user->wantecho;
179 $self->send_now('E', "0");
180 $self->send($self->msg('echow'));
181 $self->conn->echo($echo) if $self->conn->can('echo');
184 $self->tell_login('loginu');
185 $self->tell_buddies('loginb');
187 # do we need to send a forward/opernam?
188 my $lastoper = $user->lastoper || 0;
189 my $homenode = $user->homenode || "";
190 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
191 run_cmd($main::me, "forward/opernam $call");
192 $user->lastoper($main::systime + ((int rand(10)) * 86400));
195 # run a script send the output to the punter
196 my $script = new Script(lc $call) || new Script('user_default');
197 $script->run($self) if $script;
200 my $info = Route::cluster();
201 $self->send("Cluster:$info");
203 # send prompts for qth, name and things
204 $self->send($self->msg('namee1')) if !$user->name;
205 $self->send($self->msg('qthe1')) if !$user->qth;
206 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
207 $self->send($self->msg('hnodee1')) if !$user->qth;
208 $self->send($self->msg('m9')) if DXMsg::for_me($call);
210 # send out any buddy messages for other people that are online
211 foreach my $call (@{$user->buddies}) {
212 my $ref = Route::User::get($call);
214 foreach my $node (@{$ref->parent}) {
215 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
220 $self->lastmsgpoll($main::systime);
225 # This is the normal command prompt driver
234 # save this for them's that need it
235 my $rawline = $cmdline;
237 # remove leading and trailing spaces
238 $cmdline =~ s/^\s*(.*)\s*$/$1/;
240 if ($self->{state} eq 'page') {
241 my $i = $self->{pagelth};
242 my $ref = $self->{pagedata};
245 # abort if we get a line starting in with a
246 if ($cmdline =~ /^a/io) {
251 # send a tranche of data
252 while ($i-- > 0 && @$ref) {
253 my $line = shift @$ref;
254 $line =~ s/\s+$//o; # why am having to do this?
258 # reset state if none or else chuck out an intermediate prompt
260 $tot -= $self->{pagelth};
261 $self->send($self->msg('page', $tot));
263 $self->state('prompt');
265 } elsif ($self->{state} eq 'sysop') {
266 my $passwd = $self->{user}->passwd;
268 my @pw = grep {$_ !~ /\s/} split //, $passwd;
269 my @l = @{$self->{passwd}};
270 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
271 if ($cmdline =~ /$str/) {
272 $self->{priv} = $self->{user}->priv;
274 $self->send($self->msg('sorry'));
277 $self->send($self->msg('sorry'));
279 $self->state('prompt');
280 } elsif ($self->{state} eq 'passwd') {
281 my $passwd = $self->{user}->passwd;
282 if ($passwd && $cmdline eq $passwd) {
283 $self->send($self->msg('pw1'));
284 $self->state('passwd1');
286 $self->conn->{echo} = $self->conn->{decho};
287 delete $self->conn->{decho};
288 $self->send($self->msg('sorry'));
289 $self->state('prompt');
291 } elsif ($self->{state} eq 'passwd1') {
292 $self->{passwd} = $cmdline;
293 $self->send($self->msg('pw2'));
294 $self->state('passwd2');
295 } elsif ($self->{state} eq 'passwd2') {
296 if ($cmdline eq $self->{passwd}) {
297 $self->{user}->passwd($cmdline);
298 $self->send($self->msg('pw3'));
300 $self->send($self->msg('pw4'));
302 $self->conn->{echo} = $self->conn->{decho};
303 delete $self->conn->{decho};
304 $self->state('prompt');
305 } elsif ($self->{state} eq 'talk' || $self->{state} eq 'chat') {
306 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
307 for (@{$self->{talklist}}) {
308 if ($self->{state} eq 'talk') {
309 $self->send_talks($_, $self->msg('talkend'));
311 $self->send_chats($_, $self->msg('chatend', $_));
314 $self->state('prompt');
315 delete $self->{talklist};
316 } elsif ($cmdline =~ m|^/+\w+|) {
318 my $sendit = $cmdline =~ s|^/+||;
319 my @in = $self->run_cmd($cmdline);
320 $self->send_ans(@in);
321 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
322 foreach my $l (@in) {
324 if (@bad = BadWords::check($l)) {
325 $self->badcount(($self->badcount||0) + @bad);
326 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
328 for (@{$self->{talklist}}) {
329 if ($self->{state} eq 'talk') {
330 $self->send_talks($_, $l);
332 $self->send_chats($_, $l)
338 $self->send($self->{state} eq 'talk' ? $self->talk_prompt : $self->chat_prompt);
339 } elsif ($self->{talklist} && @{$self->{talklist}}) {
340 # send what has been said to whoever is in this person's talk list
342 if (@bad = BadWords::check($cmdline)) {
343 $self->badcount(($self->badcount||0) + @bad);
344 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
346 for (@{$self->{talklist}}) {
347 if ($self->{state} eq 'talk') {
348 $self->send_talks($_, $rawline);
350 $self->send_chats($_, $rawline);
354 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
355 $self->send($self->chat_prompt) if $self->{state} eq 'chat';
358 $self->state('prompt');
360 } elsif (my $func = $self->{func}) {
363 if (ref $self->{edit}) {
364 eval { @ans = $self->{edit}->$func($self, $rawline)};
366 eval { @ans = &{$self->{func}}($self, $rawline) };
369 $self->send_ans("Syserr: on stored func $self->{func}", $@);
370 delete $self->{func};
371 $self->state('prompt');
374 $self->send_ans(@ans);
376 $self->send_ans(run_cmd($self, $cmdline));
379 # check for excessive swearing
380 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
381 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
386 # send a prompt only if we are in a prompt state
387 $self->prompt() if $self->{state} =~ /^prompt/o;
390 # send out the talk messages taking into account vias and connectivity
393 my ($self, $ent, $line) = @_;
395 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
396 $to = $ent unless $to;
397 my $call = $via && $via ne '*' ? $via : $to;
398 my $clref = Route::get($call);
399 my $dxchan = $clref->dxchan if $clref;
401 $dxchan->talk($self->{call}, $to, undef, $line);
403 $self->send($self->msg('disc2', $via ? $via : $to));
404 my @l = grep { $_ ne $ent } @{$self->{talklist}};
406 $self->{talklist} = \@l;
408 delete $self->{talklist};
409 $self->state('prompt');
420 my $msgid = DXProt::nextchatmsgid();
421 $text = "#$msgid $text";
422 $main::me->normal(DXProt::pc93($target, $self->{call}, undef, $text));
430 for (@{$self->{talklist}}) {
431 my ($to, $via) = /(\S+)>(\S+)/;
435 return $self->msg($prompt, join(',', @call));
441 return $self->special_prompt('talkprompt');
447 return $self->special_prompt('chatprompt');
451 # send a load of stuff to a command user with page prompting
459 if ($self->{pagelth} && @_ > $self->{pagelth}) {
461 for ($i = $self->{pagelth}; $i-- > 0; ) {
463 $line =~ s/\s+$//o; # why am having to do this?
466 $self->{pagedata} = [ @_ ];
467 $self->state('page');
468 $self->send($self->msg('page', scalar @_));
480 # this is the thing that runs the command, it is done like this for the
481 # benefit of remote command execution
487 my $user = $self->{user};
488 my $call = $self->{call};
493 return () if length $cmdline == 0;
496 # split the command line up into parts, the first part is the command
497 my ($cmd, $args) = split /\s+/, $cmdline, 2;
498 $args = "" unless defined $args;
501 # strip out // on command only
503 $cmd =~ s|^/||g; # no leading / either
504 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
508 dbg("cmd: $cmd") if isdbg('command');
510 # alias it if possible
511 my $acmd = CmdAlias::get_cmd($cmd);
513 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
514 $args = "" unless defined $args;
515 dbg("aliased cmd: $cmd $args") if isdbg('command');
518 # first expand out the entry to a command
519 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
520 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
523 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
525 my $package = find_cmd_name($path, $fcmd);
530 dbg("package: $package") if isdbg('command');
531 eval { @ans = &$package($self, $args) };
532 return (DXDebug::shortmess($@)) if $@;
535 dbg("cmd: $cmd not found") if isdbg('command');
536 if (++$self->{errors} > $maxerrors) {
537 $self->send($self->msg('e26'));
541 return ($self->msg('e1'));
548 delete $self->{errors};
550 if (++$self->{errors} > $maxerrors) {
551 $self->send($self->msg('e26'));
556 return map {s/([^\s])\s+$/$1/; $_} @ans;
560 # This is called from inside the main cluster processing loop and is used
561 # for despatching commands that are doing some long processing job
566 my @dxchan = DXChannel::get_all();
569 foreach $dxchan (@dxchan) {
570 next if $dxchan->sort ne 'U';
572 # send a outstanding message prompt if required
573 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
574 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
575 $dxchan->lastmsgpoll($t);
578 # send a prompt if no activity out on this channel
579 if ($t >= $dxchan->t + $main::user_interval) {
580 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
585 while (my ($k, $v) = each %nothereslug) {
586 if ($main::systime >= $v + 300) {
587 delete $nothereslug{$k};
595 # finish up a user context
600 my $call = $self->call;
602 return if $self->{disconnecting}++;
604 delete $self->{senddbg};
606 my $uref = Route::User::get($call);
609 @rout = $main::routeroot->del_user($uref);
610 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
612 # issue a pc17 to everybody interested
613 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
614 $main::me->route_pc92d($main::mycall, undef, $main::routeroot, $uref);
616 confess "trying to disconnect a non existant user $call";
619 # I was the last node visited
620 $self->user->node($main::mycall);
622 # send info to all logged in thingies
623 $self->tell_login('logoutu');
624 $self->tell_buddies('logoutb');
626 LogDbg('DXCommand', "$call disconnected");
628 $self->SUPER::disconnect;
632 # short cut to output a prompt
639 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
641 my $call = $self->call;
642 my $date = cldate($main::systime);
643 my $time = ztime($main::systime);
644 my $prompt = $self->{prompt} || $self->msg('pr');
646 $call = "($call)" unless $self->here;
647 $prompt =~ s/\%C/$call/g;
648 $prompt =~ s/\%D/$date/g;
649 $prompt =~ s/\%T/$time/g;
650 $prompt =~ s/\%M/$main::mycall/g;
652 $self->send($prompt);
655 # broadcast a message to all users [except those mentioned after buffer]
658 my $pkg = shift; # ignored
659 my $s = shift; # the line to be rebroadcast
661 foreach my $dxchan (DXChannel::get_all()) {
662 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
663 next if grep $dxchan == $_, @_;
664 $dxchan->send($s); # send it
668 # gimme all the users
671 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
674 # run a script for this user
678 my $silent = shift || 0;
683 # search for the command in the cache of short->long form commands
688 my ($path, $short_cmd, $suffix) = @_;
691 # commands are lower case
692 $short_cmd = lc $short_cmd;
693 dbg("command: $path $short_cmd\n") if isdbg('command');
695 # do some checking for funny characters
696 return () if $short_cmd =~ /\/$/;
698 # return immediately if we have it
699 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
700 if ($apath && $acmd) {
701 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
702 return ($apath, $acmd);
706 my @parts = split '/', $short_cmd;
710 while (my $p = shift @parts) {
711 opendir(D, $curdir) or confess "can't open $curdir $!";
715 # if this isn't the last part
718 foreach my $l (sort @ls) {
720 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
721 dbg("got dir: $curdir/$l\n") if isdbg('command');
728 # only proceed if we find the directory asked for
729 return () unless $found;
731 foreach my $l (sort @ls) {
733 next unless $l =~ /\.$suffix$/;
734 if ($p eq substr($l, 0, length $p)) {
735 $l =~ s/\.$suffix$//;
736 $dirfn = "" unless $dirfn;
737 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
738 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
739 return ($path, "$dirfn$l");
748 # clear the command name cache
754 undef *{$_} unless /cmd_cache/;
755 dbg("Undefining cmd $_") if isdbg('command');
762 # the persistant execution of things from the command directories
765 # This allows perl programs to call functions dynamically
767 # This has been nicked directly from the perlembed pages
770 #require Devel::Symdump;
772 sub valid_package_name {
774 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
777 return "cmd_$string";
781 # this bit of magic finds a command in the offered directory
785 my $package = valid_package_name($cmdname);
786 my $filename = "$path/$cmdname.pl";
787 my $mtime = -M $filename;
789 # return if we can't find it
791 unless (defined $mtime) {
792 $errstr = DXM::msg('e1');
796 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
797 #we have compiled this subroutine already,
798 #it has not been updated on disk, nothing left to do
799 #print STDERR "already compiled $package->handler\n";
803 my $sub = readfilestr($filename);
805 $errstr = "Syserr: can't open '$filename' $!";
809 #wrap the code into a subroutine inside our unique package
810 my $eval = qq( sub $package { $sub } );
813 my @list = split /\n/, $eval;
816 dbg($_ . "\n") if isdbg('eval');
820 # get rid of any existing sub and try to compile the new one
823 if (exists $Cache{$package}) {
824 dbg("Redefining $package") if isdbg('command');
827 dbg("Defining $package") if isdbg('command');
831 $Cache{$package} = {mtime => $mtime };
843 $self->SUPER::send(dd(['cmd',$_]));
846 $self->SUPER::send(@_);
852 my ($self, $let, $buf) = @_;
853 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk' || $self->{state} eq 'chat') {
854 if ($self->{enhanced}) {
855 $self->send_later($let, $buf);
864 # send a talk message here
867 my ($self, $from, $to, $via, $line, $onode) = @_;
868 $line =~ s/\\5E/\^/g;
871 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
873 $self->local_send('T', "$to de $from: $line");
876 Log('talk', $to, $from, '<' . ($onode || '*'), $line);
877 # send a 'not here' message if required
878 unless ($self->{here} && $from ne $to) {
879 my $key = "$to$from";
880 unless (exists $nothereslug{$key}) {
882 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
883 my $name = $self->user->name || $to;
884 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
885 $nothereslug{$key} = $main::systime;
886 $dxchan->talk($to, $from, undef, $s);
903 if (!$self->{ann_talk} && $to ne $self->{call}) {
904 my $call = AnnTalk::is_talk_candidate($_[0], $text);
908 if ($self->{annfilter}) {
909 ($filter, $hops) = $self->{annfilter}->it(@_ );
910 return unless $filter;
913 unless ($self->{ann}) {
914 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
916 return if $target eq 'SYSOP' && $self->{priv} < 5;
919 $buf = dd(['ann', $to, $target, $text, @_])
921 $buf = "$to$target de $_[0]: $text";
923 $buf .= "\a\a" if $self->{beep};
925 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
939 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
941 $text =~ s/^\#\d+ //;
944 $buf = dd(['chat', $to, $target, $text, @_])
946 $buf = "$target de $_[0]: $text";
948 $buf .= "\a\a" if $self->{beep};
950 $self->local_send('C', $buf);
957 my $t = ztime($_[2]);
959 my $clth = $self->{consort} eq 'local' ? 29 : 30;
960 my $comment = substr (($_[3] || ''), 0, $clth);
961 $comment .= ' ' x ($clth - length($comment));
962 if ($self->{user}->wantgrid) {
963 my $ref = DXUser->get_current($_[4]);
965 $loc = $ref->qra || '';
966 $loc = ' ' . substr($loc, 0, 4) if $loc;
970 if ($self->{user}->wantdxitu) {
971 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
972 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
973 } elsif ($self->{user}->wantdxcq) {
974 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
975 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
976 } elsif ($self->{user}->wantusstate) {
977 $loc = ' ' . $_[13] if $_[13];
978 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
981 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
990 return unless $self->{dx};
994 if ($self->{spotsfilter}) {
995 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
996 return unless $filter;
999 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
1002 if ($self->{ve7cc}) {
1003 $buf = VE7CC::dx_spot($self, @_);
1004 } elsif ($self->{gtk}) {
1005 my ($dxloc, $byloc);
1007 my $ref = DXUser->get_current($_[4]);
1010 $byloc = substr($byloc, 0, 4) if $byloc;
1014 $spot =~ s|/\w{1,4}$||;
1015 $ref = DXUser->get_current($spot);
1018 $dxloc = substr($dxloc, 0, 4) if $dxloc;
1020 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
1023 $buf = $self->format_dx_spot(@_);
1024 $buf .= "\a\a" if $self->{beep};
1028 $self->local_send('X', $buf);
1035 my $isolate = shift;
1036 my ($filter, $hops);
1038 return unless $self->{wwv};
1040 if ($self->{wwvfilter}) {
1041 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1042 return unless $filter;
1047 $buf = dd(['wwv', @_])
1049 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1050 $buf .= "\a\a" if $self->{beep};
1053 $self->local_send('V', $buf);
1060 my $isolate = shift;
1061 my ($filter, $hops);
1063 return unless $self->{wcy};
1065 if ($self->{wcyfilter}) {
1066 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1067 return unless $filter;
1072 $buf = dd(['wcy', @_])
1074 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1075 $buf .= "\a\a" if $self->{beep};
1077 $self->local_send('Y', $buf);
1080 # broadcast debug stuff to all interested parties
1083 my $s = shift; # the line to be rebroadcast
1085 foreach my $dxchan (DXChannel::get_all) {
1086 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1087 if ($dxchan->{gtk}) {
1088 $dxchan->send_later('L', dd(['db', $s]));
1090 $dxchan->send_later('L', $s);
1101 if ($self->state eq 'enterbody') {
1102 my $loc = $self->{loc} || confess "local var gone missing" ;
1103 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1105 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1107 $self->state('prompt');
1108 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1109 push @out, $self->msg('m10');
1110 delete $loc->{lines};
1111 delete $self->{loc};
1113 $self->state('prompt');
1115 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1116 # i.e. it ain't and end or abort, therefore store the line
1119 confess "Invalid state $self->{state}";
1124 sub store_startup_script
1127 my $loc = $self->{loc} || confess "local var gone missing" ;
1129 my $call = $loc->{call} || confess "callsign gone missing";
1130 confess "lines array gone missing" unless ref $loc->{lines};
1131 my $r = Script::store($call, $loc->{lines});
1134 push @out, $self->msg('m19', $call, $r);
1136 push @out, $self->msg('m20', $call);
1139 push @out, "error opening startup script $call $!";
1144 # Import any commands contained in any files in import_cmd directory
1146 # If the filename has a recogisable callsign as some delimited part
1147 # of it, then this is the user the command will be run as.
1151 # are there any to do in this directory?
1152 return unless -d $cmdimportdir;
1153 unless (opendir(DIR, $cmdimportdir)) {
1154 LogDbg('err', "can\'t open $cmdimportdir $!");
1158 my @names = readdir(DIR);
1161 foreach $name (@names) {
1162 next if $name =~ /^\./;
1164 my $s = Script->new($name, $cmdimportdir);
1166 LogDbg('DXCommand', "Run import cmd file $name");
1167 my @cat = split /[^A-Za-z0-9]+/, $name;
1168 my ($call) = grep {is_callsign(uc $_)} @cat;
1169 $call ||= $main::mycall;
1174 $s->inscript(0); # switch off script checks
1176 if ($call eq $main::mycall) {
1177 @out = $s->run($main::me, 1);
1179 my $dxchan = DXChannel::get($call);
1181 @out = $s->run($dxchan, 1);
1183 my $u = DXUser->get($call);
1185 $dxchan = $main::me;
1186 my $old = $dxchan->{call};
1187 my $priv = $dxchan->{priv};
1188 my $user = $dxchan->{user};
1189 $dxchan->{call} = $call;
1190 $dxchan->{priv} = $u->priv;
1191 $dxchan->{user} = $u;
1192 @out = $s->run($dxchan, 1);
1193 $dxchan->{call} = $call;
1194 $dxchan->{priv} = $priv;
1195 $dxchan->{user} = $user;
1197 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1203 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1206 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1207 unlink "$cmdimportdir/$name";
1212 sub print_find_reply
1214 my ($self, $node, $target, $flag, $ms) = @_;
1215 my $sort = $flag == 2 ? "External" : "Local";
1216 $self->send("$sort $target found at $node in $ms ms" );