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 if ($self->conn->{csort} eq 'ax25') {
148 $motd = "${motd}_ax25" if -e "${motd}_ax25";
150 $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25";
153 $self->send_file($motd) if -e $motd;
155 # sort out privilege reduction
156 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
160 $nossid =~ s/-\d+$//;
162 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
163 || Filter::read_in('spots', $nossid, 0)
164 || Filter::read_in('spots', 'user_default', 0);
165 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
166 || Filter::read_in('wwv', $nossid, 0)
167 || Filter::read_in('wwv', 'user_default', 0);
168 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
169 || Filter::read_in('wcy', $nossid, 0)
170 || Filter::read_in('wcy', 'user_default', 0);
171 $self->{annfilter} = Filter::read_in('ann', $call, 0)
172 || Filter::read_in('ann', $nossid, 0)
173 || Filter::read_in('ann', 'user_default', 0) ;
175 # clean up qra locators
176 my $qra = $user->qra;
177 $qra = undef if ($qra && !DXBearing::is_qra($qra));
179 my $lat = $user->lat;
180 my $long = $user->long;
181 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
185 my $echo = $user->wantecho;
187 $self->send_now('E', "0");
188 $self->send($self->msg('echow'));
189 $self->conn->echo($echo) if $self->conn->can('echo');
192 $self->tell_login('loginu');
193 $self->tell_buddies('loginb');
195 # do we need to send a forward/opernam?
196 my $lastoper = $user->lastoper || 0;
197 my $homenode = $user->homenode || "";
198 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
199 run_cmd($main::me, "forward/opernam $call");
200 $user->lastoper($main::systime + ((int rand(10)) * 86400));
203 # run a script send the output to the punter
204 my $script = new Script(lc $call) || new Script('user_default');
205 $script->run($self) if $script;
208 my $info = Route::cluster();
209 $self->send("Cluster:$info");
211 # send prompts for qth, name and things
212 $self->send($self->msg('namee1')) if !$user->name;
213 $self->send($self->msg('qthe1')) if !$user->qth;
214 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
215 $self->send($self->msg('hnodee1')) if !$user->qth;
216 $self->send($self->msg('m9')) if DXMsg::for_me($call);
218 # send out any buddy messages for other people that are online
219 foreach my $call (@{$user->buddies}) {
220 my $ref = Route::User::get($call);
222 foreach my $node (@{$ref->parent}) {
223 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
228 $self->lastmsgpoll($main::systime);
233 # This is the normal command prompt driver
242 # save this for them's that need it
243 my $rawline = $cmdline;
245 # remove leading and trailing spaces
246 $cmdline =~ s/^\s*(.*)\s*$/$1/;
248 if ($self->{state} eq 'page') {
249 my $i = $self->{pagelth};
250 my $ref = $self->{pagedata};
253 # abort if we get a line starting in with a
254 if ($cmdline =~ /^a/io) {
259 # send a tranche of data
260 while ($i-- > 0 && @$ref) {
261 my $line = shift @$ref;
262 $line =~ s/\s+$//o; # why am having to do this?
266 # reset state if none or else chuck out an intermediate prompt
268 $tot -= $self->{pagelth};
269 $self->send($self->msg('page', $tot));
271 $self->state('prompt');
273 } elsif ($self->{state} eq 'sysop') {
274 my $passwd = $self->{user}->passwd;
276 my @pw = grep {$_ !~ /\s/} split //, $passwd;
277 my @l = @{$self->{passwd}};
278 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
279 if ($cmdline =~ /$str/) {
280 $self->{priv} = $self->{user}->priv;
282 $self->send($self->msg('sorry'));
285 $self->send($self->msg('sorry'));
287 $self->state('prompt');
288 } elsif ($self->{state} eq 'passwd') {
289 my $passwd = $self->{user}->passwd;
290 if ($passwd && $cmdline eq $passwd) {
291 $self->send($self->msg('pw1'));
292 $self->state('passwd1');
294 $self->conn->{echo} = $self->conn->{decho};
295 delete $self->conn->{decho};
296 $self->send($self->msg('sorry'));
297 $self->state('prompt');
299 } elsif ($self->{state} eq 'passwd1') {
300 $self->{passwd} = $cmdline;
301 $self->send($self->msg('pw2'));
302 $self->state('passwd2');
303 } elsif ($self->{state} eq 'passwd2') {
304 if ($cmdline eq $self->{passwd}) {
305 $self->{user}->passwd($cmdline);
306 $self->send($self->msg('pw3'));
308 $self->send($self->msg('pw4'));
310 $self->conn->{echo} = $self->conn->{decho};
311 delete $self->conn->{decho};
312 $self->state('prompt');
313 } elsif ($self->{state} eq 'talk' || $self->{state} eq 'chat') {
314 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
315 for (@{$self->{talklist}}) {
316 if ($self->{state} eq 'talk') {
317 $self->send_talks($_, $self->msg('talkend'));
319 $self->local_send('C', $self->msg('chatend', $_));
322 $self->state('prompt');
323 delete $self->{talklist};
324 } elsif ($cmdline =~ m|^/+\w+|) {
326 my $sendit = $cmdline =~ s|^/+||;
327 my @in = $self->run_cmd($cmdline);
328 $self->send_ans(@in);
329 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
330 foreach my $l (@in) {
332 if (@bad = BadWords::check($l)) {
333 $self->badcount(($self->badcount||0) + @bad);
334 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
336 for (@{$self->{talklist}}) {
337 if ($self->{state} eq 'talk') {
338 $self->send_talks($_, $l);
340 send_chats($self, $_, $l)
346 $self->send($self->{state} eq 'talk' ? $self->talk_prompt : $self->chat_prompt);
347 } elsif ($self->{talklist} && @{$self->{talklist}}) {
348 # send what has been said to whoever is in this person's talk list
350 if (@bad = BadWords::check($cmdline)) {
351 $self->badcount(($self->badcount||0) + @bad);
352 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
354 for (@{$self->{talklist}}) {
355 if ($self->{state} eq 'talk') {
356 $self->send_talks($_, $rawline);
358 send_chats($self, $_, $rawline);
362 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
363 $self->send($self->chat_prompt) if $self->{state} eq 'chat';
366 $self->state('prompt');
368 } elsif (my $func = $self->{func}) {
371 if (ref $self->{edit}) {
372 eval { @ans = $self->{edit}->$func($self, $rawline)};
374 eval { @ans = &{$self->{func}}($self, $rawline) };
377 $self->send_ans("Syserr: on stored func $self->{func}", $@);
378 delete $self->{func};
379 $self->state('prompt');
382 $self->send_ans(@ans);
384 $self->send_ans(run_cmd($self, $cmdline));
387 # check for excessive swearing
388 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
389 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
394 # send a prompt only if we are in a prompt state
395 $self->prompt() if $self->{state} =~ /^prompt/o;
398 # send out the talk messages taking into account vias and connectivity
401 my ($self, $ent, $line) = @_;
403 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
404 $to = $ent unless $to;
405 my $call = $via && $via ne '*' ? $via : $to;
406 my $clref = Route::get($call);
407 my $dxchan = $clref->dxchan if $clref;
409 $dxchan->talk($self->{call}, $to, undef, $line);
411 $self->send($self->msg('disc2', $via ? $via : $to));
412 my @l = grep { $_ ne $ent } @{$self->{talklist}};
414 $self->{talklist} = \@l;
416 delete $self->{talklist};
417 $self->state('prompt');
428 my $msgid = DXProt::nextchatmsgid();
429 $text = "#$msgid $text";
430 $main::me->normal(DXProt::pc93($target, $self->{call}, undef, $text));
438 for (@{$self->{talklist}}) {
439 my ($to, $via) = /(\S+)>(\S+)/;
443 return $self->msg($prompt, join(',', @call));
449 return $self->special_prompt('talkprompt');
455 return $self->special_prompt('chatprompt');
459 # send a load of stuff to a command user with page prompting
467 if ($self->{pagelth} && @_ > $self->{pagelth}) {
469 for ($i = $self->{pagelth}; $i-- > 0; ) {
471 $line =~ s/\s+$//o; # why am having to do this?
474 $self->{pagedata} = [ @_ ];
475 $self->state('page');
476 $self->send($self->msg('page', scalar @_));
488 # this is the thing that runs the command, it is done like this for the
489 # benefit of remote command execution
495 my $user = $self->{user};
496 my $call = $self->{call};
501 return () if length $cmdline == 0;
504 # split the command line up into parts, the first part is the command
505 my ($cmd, $args) = split /\s+/, $cmdline, 2;
506 $args = "" unless defined $args;
509 # strip out // on command only
511 $cmd =~ s|^/||g; # no leading / either
512 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
516 dbg("cmd: $cmd") if isdbg('command');
518 # alias it if possible
519 my $acmd = CmdAlias::get_cmd($cmd);
521 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
522 $args = "" unless defined $args;
523 dbg("aliased cmd: $cmd $args") if isdbg('command');
526 # first expand out the entry to a command
527 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
528 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
531 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
533 my $package = find_cmd_name($path, $fcmd);
538 dbg("package: $package") if isdbg('command');
539 eval { @ans = &$package($self, $args) };
540 return (DXDebug::shortmess($@)) if $@;
543 dbg("cmd: $cmd not found") if isdbg('command');
544 if (++$self->{errors} > $maxerrors) {
545 $self->send($self->msg('e26'));
549 return ($self->msg('e1'));
556 delete $self->{errors};
558 if (++$self->{errors} > $maxerrors) {
559 $self->send($self->msg('e26'));
564 return map {s/([^\s])\s+$/$1/; $_} @ans;
568 # This is called from inside the main cluster processing loop and is used
569 # for despatching commands that are doing some long processing job
574 my @dxchan = DXChannel::get_all();
577 foreach $dxchan (@dxchan) {
578 next if $dxchan->sort ne 'U';
580 # send a outstanding message prompt if required
581 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
582 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
583 $dxchan->lastmsgpoll($t);
586 # send a prompt if no activity out on this channel
587 if ($t >= $dxchan->t + $main::user_interval) {
588 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
593 while (my ($k, $v) = each %nothereslug) {
594 if ($main::systime >= $v + 300) {
595 delete $nothereslug{$k};
603 # finish up a user context
608 my $call = $self->call;
610 return if $self->{disconnecting}++;
612 delete $self->{senddbg};
614 my $uref = Route::User::get($call);
617 # @rout = $main::routeroot->del_user($uref);
618 @rout = DXProt::_del_thingy($main::routeroot, [$call, 0]);
620 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
622 # issue a pc17 to everybody interested
623 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
624 $main::me->route_pc92d($main::mycall, undef, $main::routeroot, $uref) unless $DXProt::pc92_slug_changes;
626 confess "trying to disconnect a non existant user $call";
629 # I was the last node visited
630 $self->user->node($main::mycall);
632 # send info to all logged in thingies
633 $self->tell_login('logoutu');
634 $self->tell_buddies('logoutb');
636 LogDbg('DXCommand', "$call disconnected");
638 $self->SUPER::disconnect;
642 # short cut to output a prompt
649 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
651 my $call = $self->call;
652 my $date = cldate($main::systime);
653 my $time = ztime($main::systime);
654 my $prompt = $self->{prompt} || $self->msg('pr');
656 $call = "($call)" unless $self->here;
657 $prompt =~ s/\%C/$call/g;
658 $prompt =~ s/\%D/$date/g;
659 $prompt =~ s/\%T/$time/g;
660 $prompt =~ s/\%M/$main::mycall/g;
662 $self->send($prompt);
665 # broadcast a message to all users [except those mentioned after buffer]
668 my $pkg = shift; # ignored
669 my $s = shift; # the line to be rebroadcast
671 foreach my $dxchan (DXChannel::get_all()) {
672 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
673 next if grep $dxchan == $_, @_;
674 $dxchan->send($s); # send it
678 # gimme all the users
681 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
684 # run a script for this user
688 my $silent = shift || 0;
693 # search for the command in the cache of short->long form commands
698 my ($path, $short_cmd, $suffix) = @_;
701 # commands are lower case
702 $short_cmd = lc $short_cmd;
703 dbg("command: $path $short_cmd\n") if isdbg('command');
705 # do some checking for funny characters
706 return () if $short_cmd =~ /\/$/;
708 # return immediately if we have it
709 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
710 if ($apath && $acmd) {
711 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
712 return ($apath, $acmd);
716 my @parts = split '/', $short_cmd;
720 while (my $p = shift @parts) {
721 opendir(D, $curdir) or confess "can't open $curdir $!";
725 # if this isn't the last part
728 foreach my $l (sort @ls) {
730 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
731 dbg("got dir: $curdir/$l\n") if isdbg('command');
738 # only proceed if we find the directory asked for
739 return () unless $found;
741 foreach my $l (sort @ls) {
743 next unless $l =~ /\.$suffix$/;
744 if ($p eq substr($l, 0, length $p)) {
745 $l =~ s/\.$suffix$//;
746 $dirfn = "" unless $dirfn;
747 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
748 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
749 return ($path, "$dirfn$l");
758 # clear the command name cache
764 undef *{$_} unless /cmd_cache/;
765 dbg("Undefining cmd $_") if isdbg('command');
772 # the persistant execution of things from the command directories
775 # This allows perl programs to call functions dynamically
777 # This has been nicked directly from the perlembed pages
780 #require Devel::Symdump;
782 sub valid_package_name {
784 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
787 return "cmd_$string";
791 # this bit of magic finds a command in the offered directory
795 my $package = valid_package_name($cmdname);
796 my $filename = "$path/$cmdname.pl";
797 my $mtime = -M $filename;
799 # return if we can't find it
801 unless (defined $mtime) {
802 $errstr = DXM::msg('e1');
806 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
807 #we have compiled this subroutine already,
808 #it has not been updated on disk, nothing left to do
809 #print STDERR "already compiled $package->handler\n";
813 my $sub = readfilestr($filename);
815 $errstr = "Syserr: can't open '$filename' $!";
819 #wrap the code into a subroutine inside our unique package
820 my $eval = qq( sub $package { $sub } );
823 my @list = split /\n/, $eval;
826 dbg($_ . "\n") if isdbg('eval');
830 # get rid of any existing sub and try to compile the new one
833 if (exists $Cache{$package}) {
834 dbg("Redefining $package") if isdbg('command');
837 dbg("Defining $package") if isdbg('command');
841 $Cache{$package} = {mtime => $mtime };
853 $self->SUPER::send(dd(['cmd',$_]));
856 $self->SUPER::send(@_);
862 my ($self, $let, $buf) = @_;
863 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk' || $self->{state} eq 'chat') {
864 if ($self->{enhanced}) {
865 $self->send_later($let, $buf);
874 # send a talk message here
877 my ($self, $from, $to, $via, $line, $onode) = @_;
878 $line =~ s/\\5E/\^/g;
881 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
883 $self->local_send('T', "$to de $from: $line");
886 Log('talk', $to, $from, '<' . ($onode || '*'), $line);
887 # send a 'not here' message if required
888 unless ($self->{here} && $from ne $to) {
889 my $key = "$to$from";
890 unless (exists $nothereslug{$key}) {
892 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
893 my $name = $self->user->name || $to;
894 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
895 $nothereslug{$key} = $main::systime;
896 $dxchan->talk($to, $from, undef, $s);
913 if (!$self->{ann_talk} && $to ne $self->{call}) {
914 my $call = AnnTalk::is_talk_candidate($_[0], $text);
918 if ($self->{annfilter}) {
919 ($filter, $hops) = $self->{annfilter}->it(@_ );
920 return unless $filter;
923 unless ($self->{ann}) {
924 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
926 return if $target eq 'SYSOP' && $self->{priv} < 5;
929 $buf = dd(['ann', $to, $target, $text, @_])
931 $buf = "$to$target de $_[0]: $text";
933 $buf .= "\a\a" if $self->{beep};
935 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
949 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
951 $text =~ s/^\#\d+ //;
954 $buf = dd(['chat', $to, $target, $text, @_])
956 $buf = "$target de $_[0]: $text";
958 $buf .= "\a\a" if $self->{beep};
960 $self->local_send('C', $buf);
967 my $t = ztime($_[2]);
969 my $clth = $self->{consort} eq 'local' ? 29 : 30;
970 my $comment = substr (($_[3] || ''), 0, $clth);
971 $comment .= ' ' x ($clth - length($comment));
972 if ($self->{user}->wantgrid) {
973 my $ref = DXUser->get_current($_[4]);
975 $loc = $ref->qra || '';
976 $loc = ' ' . substr($loc, 0, 4) if $loc;
980 if ($self->{user}->wantdxitu) {
981 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
982 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
983 } elsif ($self->{user}->wantdxcq) {
984 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
985 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
986 } elsif ($self->{user}->wantusstate) {
987 $loc = ' ' . $_[13] if $_[13];
988 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
991 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
1000 return unless $self->{dx};
1002 my ($filter, $hops);
1004 if ($self->{spotsfilter}) {
1005 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
1006 return unless $filter;
1009 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
1012 if ($self->{ve7cc}) {
1013 $buf = VE7CC::dx_spot($self, @_);
1014 } elsif ($self->{gtk}) {
1015 my ($dxloc, $byloc);
1017 my $ref = DXUser->get_current($_[4]);
1020 $byloc = substr($byloc, 0, 4) if $byloc;
1024 $spot =~ s|/\w{1,4}$||;
1025 $ref = DXUser->get_current($spot);
1028 $dxloc = substr($dxloc, 0, 4) if $dxloc;
1030 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
1033 $buf = $self->format_dx_spot(@_);
1034 $buf .= "\a\a" if $self->{beep};
1038 $self->local_send('X', $buf);
1045 my $isolate = shift;
1046 my ($filter, $hops);
1048 return unless $self->{wwv};
1050 if ($self->{wwvfilter}) {
1051 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1052 return unless $filter;
1057 $buf = dd(['wwv', @_])
1059 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1060 $buf .= "\a\a" if $self->{beep};
1063 $self->local_send('V', $buf);
1070 my $isolate = shift;
1071 my ($filter, $hops);
1073 return unless $self->{wcy};
1075 if ($self->{wcyfilter}) {
1076 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1077 return unless $filter;
1082 $buf = dd(['wcy', @_])
1084 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1085 $buf .= "\a\a" if $self->{beep};
1087 $self->local_send('Y', $buf);
1090 # broadcast debug stuff to all interested parties
1093 my $s = shift; # the line to be rebroadcast
1095 foreach my $dxchan (DXChannel::get_all) {
1096 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1097 if ($dxchan->{gtk}) {
1098 $dxchan->send_later('L', dd(['db', $s]));
1100 $dxchan->send_later('L', $s);
1111 if ($self->state eq 'enterbody') {
1112 my $loc = $self->{loc} || confess "local var gone missing" ;
1113 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1115 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1117 $self->state('prompt');
1118 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1119 push @out, $self->msg('m10');
1120 delete $loc->{lines};
1121 delete $self->{loc};
1123 $self->state('prompt');
1125 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1126 # i.e. it ain't and end or abort, therefore store the line
1129 confess "Invalid state $self->{state}";
1134 sub store_startup_script
1137 my $loc = $self->{loc} || confess "local var gone missing" ;
1139 my $call = $loc->{call} || confess "callsign gone missing";
1140 confess "lines array gone missing" unless ref $loc->{lines};
1141 my $r = Script::store($call, $loc->{lines});
1144 push @out, $self->msg('m19', $call, $r);
1146 push @out, $self->msg('m20', $call);
1149 push @out, "error opening startup script $call $!";
1154 # Import any commands contained in any files in import_cmd directory
1156 # If the filename has a recogisable callsign as some delimited part
1157 # of it, then this is the user the command will be run as.
1161 # are there any to do in this directory?
1162 return unless -d $cmdimportdir;
1163 unless (opendir(DIR, $cmdimportdir)) {
1164 LogDbg('err', "can\'t open $cmdimportdir $!");
1168 my @names = readdir(DIR);
1171 foreach $name (@names) {
1172 next if $name =~ /^\./;
1174 my $s = Script->new($name, $cmdimportdir);
1176 LogDbg('DXCommand', "Run import cmd file $name");
1177 my @cat = split /[^A-Za-z0-9]+/, $name;
1178 my ($call) = grep {is_callsign(uc $_)} @cat;
1179 $call ||= $main::mycall;
1184 $s->inscript(0); # switch off script checks
1186 if ($call eq $main::mycall) {
1187 @out = $s->run($main::me, 1);
1189 my $dxchan = DXChannel::get($call);
1191 @out = $s->run($dxchan, 1);
1193 my $u = DXUser->get($call);
1195 $dxchan = $main::me;
1196 my $old = $dxchan->{call};
1197 my $priv = $dxchan->{priv};
1198 my $user = $dxchan->{user};
1199 $dxchan->{call} = $call;
1200 $dxchan->{priv} = $u->priv;
1201 $dxchan->{user} = $u;
1202 @out = $s->run($dxchan, 1);
1203 $dxchan->{call} = $call;
1204 $dxchan->{priv} = $priv;
1205 $dxchan->{user} = $user;
1207 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1213 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1216 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1217 unlink "$cmdimportdir/$name";
1222 sub print_find_reply
1224 my ($self, $node, $target, $flag, $ms) = @_;
1225 my $sort = $flag == 2 ? "External" : "Local";
1226 $self->send("$sort $target found at $node in $ms ms" );