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 = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
59 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
60 $main::build += $VERSION;
61 $main::branch += $BRANCH;
64 # obtain a new connection this is derived from dxchannel
69 my $self = DXChannel::alloc(@_);
71 # routing, this must go out here to prevent race condx
74 my @rout = $main::routeroot->add_user($call, Route::here(1));
76 # ALWAYS output the user
77 my $ref = Route::User::get($call);
79 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref);
80 $main::me->route_pc92a($main::mycall, undef, $ref);
86 # this is how a a connection starts, you get a hello message and the motd with
87 # possibly some other messages asking you to set various things up if you are
88 # new (or nearly new and slacking) user.
92 my ($self, $line, $sort) = @_;
93 my $user = $self->{user};
94 my $call = $self->{call};
95 my $name = $user->{name};
98 my $host = $self->{conn}->{peerhost};
99 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
101 LogDbg('DXCommand', "$call connected from $host");
103 $self->{name} = $name ? $name : $call;
104 $self->send($self->msg('l2',$self->{name}));
105 $self->state('prompt'); # a bit of room for further expansion, passwords etc
106 $self->{priv} = $user->priv || 0;
107 $self->{lang} = $user->lang || $main::lang || 'en';
108 my $pagelth = $user->pagelth;
109 $pagelth = $default_pagelth unless defined $pagelth;
110 $self->{pagelth} = $pagelth;
111 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
112 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
113 $self->{consort} = $line; # save the connection type
115 # set some necessary flags on the user if they are connecting
116 $self->{beep} = $user->wantbeep;
117 $self->{ann} = $user->wantann;
118 $self->{wwv} = $user->wantwwv;
119 $self->{wcy} = $user->wantwcy;
120 $self->{talk} = $user->wanttalk;
121 $self->{wx} = $user->wantwx;
122 $self->{dx} = $user->wantdx;
123 $self->{logininfo} = $user->wantlogininfo;
124 $self->{ann_talk} = $user->wantann_talk;
126 $self->{prompt} = $user->prompt if $user->prompt;
128 # sort out new dx spot stuff
129 $user->wantdxcq(0) unless defined $user->{wantdxcq};
130 $user->wantdxitu(0) unless defined $user->{wantdxitu};
131 $user->wantusstate(0) unless defined $user->{wantusstate};
133 # sort out registration
134 if ($main::reqreg == 1) {
135 $self->{registered} = $user->registered;
136 } elsif ($main::reqreg == 2) {
137 $self->{registered} = !$user->registered;
139 $self->{registered} = 1;
143 # decide which motd to send
145 unless ($self->{registered}) {
146 $motd = "${main::motd}_nor_$self->{lang}";
147 $motd = "${main::motd}_nor" unless -e $motd;
149 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
150 $motd = $main::motd unless $motd && -e $motd;
151 $self->send_file($motd) if -e $motd;
153 # sort out privilege reduction
154 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
158 $nossid =~ s/-\d+$//;
160 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
161 || Filter::read_in('spots', $nossid, 0)
162 || Filter::read_in('spots', 'user_default', 0);
163 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
164 || Filter::read_in('wwv', $nossid, 0)
165 || Filter::read_in('wwv', 'user_default', 0);
166 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
167 || Filter::read_in('wcy', $nossid, 0)
168 || Filter::read_in('wcy', 'user_default', 0);
169 $self->{annfilter} = Filter::read_in('ann', $call, 0)
170 || Filter::read_in('ann', $nossid, 0)
171 || Filter::read_in('ann', 'user_default', 0) ;
173 # clean up qra locators
174 my $qra = $user->qra;
175 $qra = undef if ($qra && !DXBearing::is_qra($qra));
177 my $lat = $user->lat;
178 my $long = $user->long;
179 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
183 my $echo = $user->wantecho;
185 $self->send_now('E', "0");
186 $self->send($self->msg('echow'));
187 $self->conn->echo($echo) if $self->conn->can('echo');
190 $self->tell_login('loginu');
191 $self->tell_buddies('loginb');
193 # do we need to send a forward/opernam?
194 my $lastoper = $user->lastoper || 0;
195 my $homenode = $user->homenode || "";
196 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
197 run_cmd($main::me, "forward/opernam $call");
198 $user->lastoper($main::systime + ((int rand(10)) * 86400));
201 # run a script send the output to the punter
202 my $script = new Script(lc $call) || new Script('user_default');
203 $script->run($self) if $script;
206 my $info = Route::cluster();
207 $self->send("Cluster:$info");
209 # send prompts for qth, name and things
210 $self->send($self->msg('namee1')) if !$user->name;
211 $self->send($self->msg('qthe1')) if !$user->qth;
212 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
213 $self->send($self->msg('hnodee1')) if !$user->qth;
214 $self->send($self->msg('m9')) if DXMsg::for_me($call);
216 # send out any buddy messages for other people that are online
217 foreach my $call (@{$user->buddies}) {
218 my $ref = Route::User::get($call);
220 foreach my $node (@{$ref->parent}) {
221 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
226 $self->lastmsgpoll($main::systime);
231 # This is the normal command prompt driver
240 # save this for them's that need it
241 my $rawline = $cmdline;
243 # remove leading and trailing spaces
244 $cmdline =~ s/^\s*(.*)\s*$/$1/;
246 if ($self->{state} eq 'page') {
247 my $i = $self->{pagelth};
248 my $ref = $self->{pagedata};
251 # abort if we get a line starting in with a
252 if ($cmdline =~ /^a/io) {
257 # send a tranche of data
258 while ($i-- > 0 && @$ref) {
259 my $line = shift @$ref;
260 $line =~ s/\s+$//o; # why am having to do this?
264 # reset state if none or else chuck out an intermediate prompt
266 $tot -= $self->{pagelth};
267 $self->send($self->msg('page', $tot));
269 $self->state('prompt');
271 } elsif ($self->{state} eq 'sysop') {
272 my $passwd = $self->{user}->passwd;
274 my @pw = grep {$_ !~ /\s/} split //, $passwd;
275 my @l = @{$self->{passwd}};
276 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
277 if ($cmdline =~ /$str/) {
278 $self->{priv} = $self->{user}->priv;
280 $self->send($self->msg('sorry'));
283 $self->send($self->msg('sorry'));
285 $self->state('prompt');
286 } elsif ($self->{state} eq 'passwd') {
287 my $passwd = $self->{user}->passwd;
288 if ($passwd && $cmdline eq $passwd) {
289 $self->send($self->msg('pw1'));
290 $self->state('passwd1');
292 $self->conn->{echo} = $self->conn->{decho};
293 delete $self->conn->{decho};
294 $self->send($self->msg('sorry'));
295 $self->state('prompt');
297 } elsif ($self->{state} eq 'passwd1') {
298 $self->{passwd} = $cmdline;
299 $self->send($self->msg('pw2'));
300 $self->state('passwd2');
301 } elsif ($self->{state} eq 'passwd2') {
302 if ($cmdline eq $self->{passwd}) {
303 $self->{user}->passwd($cmdline);
304 $self->send($self->msg('pw3'));
306 $self->send($self->msg('pw4'));
308 $self->conn->{echo} = $self->conn->{decho};
309 delete $self->conn->{decho};
310 $self->state('prompt');
311 } elsif ($self->{state} eq 'talk') {
312 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
313 for (@{$self->{talklist}}) {
314 $self->send_talks($_, $self->msg('talkend'));
316 $self->state('prompt');
317 delete $self->{talklist};
318 } elsif ($cmdline =~ m|^/+\w+|) {
320 my $sendit = $cmdline =~ s|^/+||;
321 my @in = $self->run_cmd($cmdline);
322 $self->send_ans(@in);
323 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
324 foreach my $l (@in) {
326 if (@bad = BadWords::check($l)) {
327 $self->badcount(($self->badcount||0) + @bad);
328 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
330 for (@{$self->{talklist}}) {
331 $self->send_talks($_, $l);
336 $self->send($self->talk_prompt);
337 } elsif ($self->{talklist} && @{$self->{talklist}}) {
338 # send what has been said to whoever is in this person's talk list
340 if (@bad = BadWords::check($cmdline)) {
341 $self->badcount(($self->badcount||0) + @bad);
342 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
344 for (@{$self->{talklist}}) {
345 $self->send_talks($_, $rawline);
348 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
351 $self->state('prompt');
353 } elsif (my $func = $self->{func}) {
356 if (ref $self->{edit}) {
357 eval { @ans = $self->{edit}->$func($self, $rawline)};
359 eval { @ans = &{$self->{func}}($self, $rawline) };
362 $self->send_ans("Syserr: on stored func $self->{func}", $@);
363 delete $self->{func};
364 $self->state('prompt');
367 $self->send_ans(@ans);
369 $self->send_ans(run_cmd($self, $cmdline));
372 # check for excessive swearing
373 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
374 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
379 # send a prompt only if we are in a prompt state
380 $self->prompt() if $self->{state} =~ /^prompt/o;
383 # send out the talk messages taking into account vias and connectivity
386 my ($self, $ent, $line) = @_;
388 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
389 $to = $ent unless $to;
390 my $call = $via ? $via : $to;
391 my $clref = Route::get($call);
392 my $dxchan = $clref->dxchan if $clref;
394 $dxchan->talk($self->{call}, $to, $via, $line);
396 $self->send($self->msg('disc2', $via ? $via : $to));
397 my @l = grep { $_ ne $ent } @{$self->{talklist}};
399 $self->{talklist} = \@l;
401 delete $self->{talklist};
402 $self->state('prompt');
411 for (@{$self->{talklist}}) {
412 my ($to, $via) = /(\S+)>(\S+)/;
416 return $self->msg('talkprompt', join(',', @call));
420 # send a load of stuff to a command user with page prompting
428 if ($self->{pagelth} && @_ > $self->{pagelth}) {
430 for ($i = $self->{pagelth}; $i-- > 0; ) {
432 $line =~ s/\s+$//o; # why am having to do this?
435 $self->{pagedata} = [ @_ ];
436 $self->state('page');
437 $self->send($self->msg('page', scalar @_));
449 # this is the thing that runs the command, it is done like this for the
450 # benefit of remote command execution
456 my $user = $self->{user};
457 my $call = $self->{call};
462 return () if length $cmdline == 0;
465 # split the command line up into parts, the first part is the command
466 my ($cmd, $args) = split /\s+/, $cmdline, 2;
467 $args = "" unless defined $args;
470 # strip out // on command only
472 $cmd =~ s|^/||g; # no leading / either
473 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
477 dbg("cmd: $cmd") if isdbg('command');
479 # alias it if possible
480 my $acmd = CmdAlias::get_cmd($cmd);
482 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
483 $args = "" unless defined $args;
484 dbg("aliased cmd: $cmd $args") if isdbg('command');
487 # first expand out the entry to a command
488 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
489 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
492 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
494 my $package = find_cmd_name($path, $fcmd);
499 dbg("package: $package") if isdbg('command');
500 eval { @ans = &$package($self, $args) };
501 return (DXDebug::shortmess($@)) if $@;
504 dbg("cmd: $cmd not found") if isdbg('command');
505 if (++$self->{errors} > $maxerrors) {
506 $self->send($self->msg('e26'));
510 return ($self->msg('e1'));
517 delete $self->{errors};
519 if (++$self->{errors} > $maxerrors) {
520 $self->send($self->msg('e26'));
525 return map {s/([^\s])\s+$/$1/; $_} @ans;
529 # This is called from inside the main cluster processing loop and is used
530 # for despatching commands that are doing some long processing job
535 my @dxchan = DXChannel::get_all();
538 foreach $dxchan (@dxchan) {
539 next if $dxchan->sort ne 'U';
541 # send a outstanding message prompt if required
542 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
543 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
544 $dxchan->lastmsgpoll($t);
547 # send a prompt if no activity out on this channel
548 if ($t >= $dxchan->t + $main::user_interval) {
549 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
554 while (my ($k, $v) = each %nothereslug) {
555 if ($main::systime >= $v + 300) {
556 delete $nothereslug{$k};
564 # finish up a user context
569 my $call = $self->call;
571 return if $self->{disconnecting}++;
573 delete $self->{senddbg};
575 my $uref = Route::User::get($call);
578 @rout = $main::routeroot->del_user($uref);
579 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
581 # issue a pc17 to everybody interested
582 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
583 $main::me->route_pc92d($main::mycall, undef, $uref);
585 confess "trying to disconnect a non existant user $call";
588 # I was the last node visited
589 $self->user->node($main::mycall);
591 # send info to all logged in thingies
592 $self->tell_login('logoutu');
593 $self->tell_buddies('logoutb');
595 LogDbg('DXCommand', "$call disconnected");
597 $self->SUPER::disconnect;
601 # short cut to output a prompt
608 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
610 my $call = $self->call;
611 my $date = cldate($main::systime);
612 my $time = ztime($main::systime);
613 my $prompt = $self->{prompt} || $self->msg('pr');
615 $call = "($call)" unless $self->here;
616 $prompt =~ s/\%C/$call/g;
617 $prompt =~ s/\%D/$date/g;
618 $prompt =~ s/\%T/$time/g;
619 $prompt =~ s/\%M/$main::mycall/g;
621 $self->send($prompt);
624 # broadcast a message to all users [except those mentioned after buffer]
627 my $pkg = shift; # ignored
628 my $s = shift; # the line to be rebroadcast
630 foreach my $dxchan (DXChannel::get_all()) {
631 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
632 next if grep $dxchan == $_, @_;
633 $dxchan->send($s); # send it
637 # gimme all the users
640 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
643 # run a script for this user
647 my $silent = shift || 0;
652 # search for the command in the cache of short->long form commands
657 my ($path, $short_cmd, $suffix) = @_;
660 # commands are lower case
661 $short_cmd = lc $short_cmd;
662 dbg("command: $path $short_cmd\n") if isdbg('command');
664 # do some checking for funny characters
665 return () if $short_cmd =~ /\/$/;
667 # return immediately if we have it
668 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
669 if ($apath && $acmd) {
670 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
671 return ($apath, $acmd);
675 my @parts = split '/', $short_cmd;
679 while (my $p = shift @parts) {
680 opendir(D, $curdir) or confess "can't open $curdir $!";
684 # if this isn't the last part
687 foreach my $l (sort @ls) {
689 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
690 dbg("got dir: $curdir/$l\n") if isdbg('command');
697 # only proceed if we find the directory asked for
698 return () unless $found;
700 foreach my $l (sort @ls) {
702 next unless $l =~ /\.$suffix$/;
703 if ($p eq substr($l, 0, length $p)) {
704 $l =~ s/\.$suffix$//;
705 $dirfn = "" unless $dirfn;
706 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
707 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
708 return ($path, "$dirfn$l");
717 # clear the command name cache
723 undef *{$_} unless /cmd_cache/;
724 dbg("Undefining cmd $_") if isdbg('command');
731 # the persistant execution of things from the command directories
734 # This allows perl programs to call functions dynamically
736 # This has been nicked directly from the perlembed pages
739 #require Devel::Symdump;
741 sub valid_package_name {
743 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
746 return "cmd_$string";
750 # this bit of magic finds a command in the offered directory
754 my $package = valid_package_name($cmdname);
755 my $filename = "$path/$cmdname.pl";
756 my $mtime = -M $filename;
758 # return if we can't find it
760 unless (defined $mtime) {
761 $errstr = DXM::msg('e1');
765 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
766 #we have compiled this subroutine already,
767 #it has not been updated on disk, nothing left to do
768 #print STDERR "already compiled $package->handler\n";
772 my $sub = readfilestr($filename);
774 $errstr = "Syserr: can't open '$filename' $!";
778 #wrap the code into a subroutine inside our unique package
779 my $eval = qq( sub $package { $sub } );
782 my @list = split /\n/, $eval;
785 dbg($_ . "\n") if isdbg('eval');
789 # get rid of any existing sub and try to compile the new one
792 if (exists $Cache{$package}) {
793 dbg("Redefining $package") if isdbg('command');
796 dbg("Defining $package") if isdbg('command');
800 $Cache{$package} = {mtime => $mtime };
812 $self->SUPER::send(dd(['cmd',$_]));
815 $self->SUPER::send(@_);
821 my ($self, $let, $buf) = @_;
822 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
823 if ($self->{enhanced}) {
824 $self->send_later($let, $buf);
833 # send a talk message here
836 my ($self, $from, $to, $via, $line) = @_;
837 $line =~ s/\\5E/\^/g;
840 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
842 $self->local_send('T', "$to de $from: $line");
845 Log('talk', $to, $from, $via?$via:$main::mycall, $line);
846 # send a 'not here' message if required
847 unless ($self->{here} && $from ne $to) {
848 my $key = "$to$from";
849 unless (exists $nothereslug{$key}) {
851 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
852 my $name = $self->user->name || $to;
853 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
854 $nothereslug{$key} = $main::systime;
855 $dxchan->talk($to, $from, undef, $s);
872 if (!$self->{ann_talk} && $to ne $self->{call}) {
873 my $call = AnnTalk::is_talk_candidate($_[0], $text);
877 if ($self->{annfilter}) {
878 ($filter, $hops) = $self->{annfilter}->it(@_ );
879 return unless $filter;
882 unless ($self->{ann}) {
883 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
885 return if $target eq 'SYSOP' && $self->{priv} < 5;
888 $buf = dd(['ann', $to, $target, $text, @_])
890 $buf = "$to$target de $_[0]: $text";
892 $buf .= "\a\a" if $self->{beep};
894 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
908 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
910 $text =~ s/^\#\d+ //;
913 $buf = dd(['chat', $to, $target, $text, @_])
915 $buf = "$target de $_[0]: $text";
917 $buf .= "\a\a" if $self->{beep};
919 $self->local_send('C', $buf);
926 my $t = ztime($_[2]);
928 my $clth = $self->{consort} eq 'local' ? 29 : 30;
929 my $comment = substr $_[3], 0, $clth;
930 $comment .= ' ' x ($clth - length($comment));
931 if ($self->{user}->wantgrid) {
932 my $ref = DXUser->get_current($_[4]);
934 $loc = $ref->qra || '';
935 $loc = ' ' . substr($loc, 0, 4) if $loc;
939 if ($self->{user}->wantdxitu) {
940 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
941 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
942 } elsif ($self->{user}->wantdxcq) {
943 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
944 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
945 } elsif ($self->{user}->wantusstate) {
946 $loc = ' ' . $_[13] if $_[13];
947 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
950 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
959 return unless $self->{dx};
963 if ($self->{spotsfilter}) {
964 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
965 return unless $filter;
968 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
971 if ($self->{ve7cc}) {
972 $buf = VE7CC::dx_spot($self, @_);
973 } elsif ($self->{gtk}) {
976 my $ref = DXUser->get_current($_[4]);
979 $byloc = substr($byloc, 0, 4) if $byloc;
983 $spot =~ s|/\w{1,4}$||;
984 $ref = DXUser->get_current($spot);
987 $dxloc = substr($dxloc, 0, 4) if $dxloc;
989 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
992 $buf = $self->format_dx_spot(@_);
993 $buf .= "\a\a" if $self->{beep};
997 $self->local_send('X', $buf);
1004 my $isolate = shift;
1005 my ($filter, $hops);
1007 return unless $self->{wwv};
1009 if ($self->{wwvfilter}) {
1010 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1011 return unless $filter;
1016 $buf = dd(['wwv', @_])
1018 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1019 $buf .= "\a\a" if $self->{beep};
1022 $self->local_send('V', $buf);
1029 my $isolate = shift;
1030 my ($filter, $hops);
1032 return unless $self->{wcy};
1034 if ($self->{wcyfilter}) {
1035 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1036 return unless $filter;
1041 $buf = dd(['wcy', @_])
1043 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1044 $buf .= "\a\a" if $self->{beep};
1046 $self->local_send('Y', $buf);
1049 # broadcast debug stuff to all interested parties
1052 my $s = shift; # the line to be rebroadcast
1054 foreach my $dxchan (DXChannel::get_all) {
1055 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1056 if ($dxchan->{gtk}) {
1057 $dxchan->send_later('L', dd(['db', $s]));
1059 $dxchan->send_later('L', $s);
1070 if ($self->state eq 'enterbody') {
1071 my $loc = $self->{loc} || confess "local var gone missing" ;
1072 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1074 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1076 $self->state('prompt');
1077 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1078 push @out, $self->msg('m10');
1079 delete $loc->{lines};
1080 delete $self->{loc};
1082 $self->state('prompt');
1084 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1085 # i.e. it ain't and end or abort, therefore store the line
1088 confess "Invalid state $self->{state}";
1093 sub store_startup_script
1096 my $loc = $self->{loc} || confess "local var gone missing" ;
1098 my $call = $loc->{call} || confess "callsign gone missing";
1099 confess "lines array gone missing" unless ref $loc->{lines};
1100 my $r = Script::store($call, $loc->{lines});
1103 push @out, $self->msg('m19', $call, $r);
1105 push @out, $self->msg('m20', $call);
1108 push @out, "error opening startup script $call $!";
1113 # Import any commands contained in any files in import_cmd directory
1115 # If the filename has a recogisable callsign as some delimited part
1116 # of it, then this is the user the command will be run as.
1120 # are there any to do in this directory?
1121 return unless -d $cmdimportdir;
1122 unless (opendir(DIR, $cmdimportdir)) {
1123 LogDbg('err', "can\'t open $cmdimportdir $!");
1127 my @names = readdir(DIR);
1130 foreach $name (@names) {
1131 next if $name =~ /^\./;
1133 my $s = Script->new($name, $cmdimportdir);
1135 LogDbg('DXCommand', "Run import cmd file $name");
1136 my @cat = split /[^A-Za-z0-9]+/, $name;
1137 my ($call) = grep {is_callsign(uc $_)} @cat;
1138 $call ||= $main::mycall;
1143 $s->inscript(0); # switch off script checks
1145 if ($call eq $main::mycall) {
1146 @out = $s->run($main::me, 1);
1148 my $dxchan = DXChannel::get($call);
1150 @out = $s->run($dxchan, 1);
1152 my $u = DXUser->get($call);
1154 $dxchan = $main::me;
1155 my $old = $dxchan->{call};
1156 my $priv = $dxchan->{priv};
1157 my $user = $dxchan->{user};
1158 $dxchan->{call} = $call;
1159 $dxchan->{priv} = $u->priv;
1160 $dxchan->{user} = $u;
1161 @out = $s->run($dxchan, 1);
1162 $dxchan->{call} = $call;
1163 $dxchan->{priv} = $priv;
1164 $dxchan->{user} = $user;
1166 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1172 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1175 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1176 unlink "$cmdimportdir/$name";