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);
72 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref) if $ref;
77 # this is how a a connection starts, you get a hello message and the motd with
78 # possibly some other messages asking you to set various things up if you are
79 # new (or nearly new and slacking) user.
83 my ($self, $line, $sort) = @_;
84 my $user = $self->{user};
85 my $call = $self->{call};
86 my $name = $user->{name};
89 my $host = $self->{conn}->{peerhost};
90 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
92 LogDbg('DXCommand', "$call connected from $host");
94 $self->{name} = $name ? $name : $call;
95 $self->send($self->msg('l2',$self->{name}));
96 $self->state('prompt'); # a bit of room for further expansion, passwords etc
97 $self->{priv} = $user->priv || 0;
98 $self->{lang} = $user->lang || $main::lang || 'en';
99 my $pagelth = $user->pagelth;
100 $pagelth = $default_pagelth unless defined $pagelth;
101 $self->{pagelth} = $pagelth;
102 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
103 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
104 $self->{consort} = $line; # save the connection type
106 # set some necessary flags on the user if they are connecting
107 $self->{beep} = $user->wantbeep;
108 $self->{ann} = $user->wantann;
109 $self->{wwv} = $user->wantwwv;
110 $self->{wcy} = $user->wantwcy;
111 $self->{talk} = $user->wanttalk;
112 $self->{wx} = $user->wantwx;
113 $self->{dx} = $user->wantdx;
114 $self->{logininfo} = $user->wantlogininfo;
115 $self->{ann_talk} = $user->wantann_talk;
117 $self->{prompt} = $user->prompt if $user->prompt;
119 # sort out new dx spot stuff
120 $user->wantdxcq(0) unless defined $user->{wantdxcq};
121 $user->wantdxitu(0) unless defined $user->{wantdxitu};
122 $user->wantusstate(0) unless defined $user->{wantusstate};
124 # sort out registration
125 if ($main::reqreg == 1) {
126 $self->{registered} = $user->registered;
127 } elsif ($main::reqreg == 2) {
128 $self->{registered} = !$user->registered;
130 $self->{registered} = 1;
134 # decide which motd to send
136 unless ($self->{registered}) {
137 $motd = "${main::motd}_nor_$self->{lang}";
138 $motd = "${main::motd}_nor" unless -e $motd;
140 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
141 $motd = $main::motd unless $motd && -e $motd;
142 $self->send_file($motd) if -e $motd;
144 # sort out privilege reduction
145 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
149 $nossid =~ s/-\d+$//;
151 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
152 || Filter::read_in('spots', $nossid, 0)
153 || Filter::read_in('spots', 'user_default', 0);
154 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
155 || Filter::read_in('wwv', $nossid, 0)
156 || Filter::read_in('wwv', 'user_default', 0);
157 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
158 || Filter::read_in('wcy', $nossid, 0)
159 || Filter::read_in('wcy', 'user_default', 0);
160 $self->{annfilter} = Filter::read_in('ann', $call, 0)
161 || Filter::read_in('ann', $nossid, 0)
162 || Filter::read_in('ann', 'user_default', 0) ;
164 # clean up qra locators
165 my $qra = $user->qra;
166 $qra = undef if ($qra && !DXBearing::is_qra($qra));
168 my $lat = $user->lat;
169 my $long = $user->long;
170 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
174 my $echo = $user->wantecho;
176 $self->send_now('E', "0");
177 $self->send($self->msg('echow'));
178 $self->conn->echo($echo) if $self->conn->can('echo');
181 $self->tell_login('loginu');
182 $self->tell_buddies('loginb');
184 # do we need to send a forward/opernam?
185 my $lastoper = $user->lastoper || 0;
186 my $homenode = $user->homenode || "";
187 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
188 run_cmd($main::me, "forward/opernam $call");
189 $user->lastoper($main::systime + ((int rand(10)) * 86400));
192 # run a script send the output to the punter
193 my $script = new Script(lc $call) || new Script('user_default');
194 $script->run($self) if $script;
197 my $info = Route::cluster();
198 $self->send("Cluster:$info");
200 # send prompts for qth, name and things
201 $self->send($self->msg('namee1')) if !$user->name;
202 $self->send($self->msg('qthe1')) if !$user->qth;
203 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
204 $self->send($self->msg('hnodee1')) if !$user->qth;
205 $self->send($self->msg('m9')) if DXMsg::for_me($call);
207 # send out any buddy messages for other people that are online
208 foreach my $call (@{$user->buddies}) {
209 my $ref = Route::User::get($call);
211 foreach my $node (@{$ref->parent}) {
212 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
217 $self->lastmsgpoll($main::systime);
222 # This is the normal command prompt driver
231 # save this for them's that need it
232 my $rawline = $cmdline;
234 # remove leading and trailing spaces
235 $cmdline =~ s/^\s*(.*)\s*$/$1/;
237 if ($self->{state} eq 'page') {
238 my $i = $self->{pagelth};
239 my $ref = $self->{pagedata};
242 # abort if we get a line starting in with a
243 if ($cmdline =~ /^a/io) {
248 # send a tranche of data
249 while ($i-- > 0 && @$ref) {
250 my $line = shift @$ref;
251 $line =~ s/\s+$//o; # why am having to do this?
255 # reset state if none or else chuck out an intermediate prompt
257 $tot -= $self->{pagelth};
258 $self->send($self->msg('page', $tot));
260 $self->state('prompt');
262 } elsif ($self->{state} eq 'sysop') {
263 my $passwd = $self->{user}->passwd;
265 my @pw = grep {$_ !~ /\s/} split //, $passwd;
266 my @l = @{$self->{passwd}};
267 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
268 if ($cmdline =~ /$str/) {
269 $self->{priv} = $self->{user}->priv;
271 $self->send($self->msg('sorry'));
274 $self->send($self->msg('sorry'));
276 $self->state('prompt');
277 } elsif ($self->{state} eq 'passwd') {
278 my $passwd = $self->{user}->passwd;
279 if ($passwd && $cmdline eq $passwd) {
280 $self->send($self->msg('pw1'));
281 $self->state('passwd1');
283 $self->conn->{echo} = $self->conn->{decho};
284 delete $self->conn->{decho};
285 $self->send($self->msg('sorry'));
286 $self->state('prompt');
288 } elsif ($self->{state} eq 'passwd1') {
289 $self->{passwd} = $cmdline;
290 $self->send($self->msg('pw2'));
291 $self->state('passwd2');
292 } elsif ($self->{state} eq 'passwd2') {
293 if ($cmdline eq $self->{passwd}) {
294 $self->{user}->passwd($cmdline);
295 $self->send($self->msg('pw3'));
297 $self->send($self->msg('pw4'));
299 $self->conn->{echo} = $self->conn->{decho};
300 delete $self->conn->{decho};
301 $self->state('prompt');
302 } elsif ($self->{state} eq 'talk') {
303 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
304 for (@{$self->{talklist}}) {
305 $self->send_talks($_, $self->msg('talkend'));
307 $self->state('prompt');
308 delete $self->{talklist};
309 } elsif ($cmdline =~ m|^/+\w+|) {
311 my $sendit = $cmdline =~ s|^/+||;
312 my @in = $self->run_cmd($cmdline);
313 $self->send_ans(@in);
314 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
315 foreach my $l (@in) {
317 if (@bad = BadWords::check($l)) {
318 $self->badcount(($self->badcount||0) + @bad);
319 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
321 for (@{$self->{talklist}}) {
322 $self->send_talks($_, $l);
327 $self->send($self->talk_prompt);
328 } elsif ($self->{talklist} && @{$self->{talklist}}) {
329 # send what has been said to whoever is in this person's talk list
331 if (@bad = BadWords::check($cmdline)) {
332 $self->badcount(($self->badcount||0) + @bad);
333 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
335 for (@{$self->{talklist}}) {
336 $self->send_talks($_, $rawline);
339 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
342 $self->state('prompt');
344 } elsif (my $func = $self->{func}) {
347 if (ref $self->{edit}) {
348 eval { @ans = $self->{edit}->$func($self, $rawline)};
350 eval { @ans = &{$self->{func}}($self, $rawline) };
353 $self->send_ans("Syserr: on stored func $self->{func}", $@);
354 delete $self->{func};
355 $self->state('prompt');
358 $self->send_ans(@ans);
360 $self->send_ans(run_cmd($self, $cmdline));
363 # check for excessive swearing
364 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
365 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
370 # send a prompt only if we are in a prompt state
371 $self->prompt() if $self->{state} =~ /^prompt/o;
374 # send out the talk messages taking into account vias and connectivity
377 my ($self, $ent, $line) = @_;
379 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
380 $to = $ent unless $to;
381 my $call = $via ? $via : $to;
382 my $clref = Route::get($call);
383 my $dxchan = $clref->dxchan if $clref;
385 $dxchan->talk($self->{call}, $to, $via, $line);
387 $self->send($self->msg('disc2', $via ? $via : $to));
388 my @l = grep { $_ ne $ent } @{$self->{talklist}};
390 $self->{talklist} = \@l;
392 delete $self->{talklist};
393 $self->state('prompt');
402 for (@{$self->{talklist}}) {
403 my ($to, $via) = /(\S+)>(\S+)/;
407 return $self->msg('talkprompt', join(',', @call));
411 # send a load of stuff to a command user with page prompting
419 if ($self->{pagelth} && @_ > $self->{pagelth}) {
421 for ($i = $self->{pagelth}; $i-- > 0; ) {
423 $line =~ s/\s+$//o; # why am having to do this?
426 $self->{pagedata} = [ @_ ];
427 $self->state('page');
428 $self->send($self->msg('page', scalar @_));
440 # this is the thing that runs the command, it is done like this for the
441 # benefit of remote command execution
447 my $user = $self->{user};
448 my $call = $self->{call};
453 return () if length $cmdline == 0;
456 # split the command line up into parts, the first part is the command
457 my ($cmd, $args) = split /\s+/, $cmdline, 2;
458 $args = "" unless defined $args;
461 # strip out // on command only
463 $cmd =~ s|^/||g; # no leading / either
464 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
468 dbg("cmd: $cmd") if isdbg('command');
470 # alias it if possible
471 my $acmd = CmdAlias::get_cmd($cmd);
473 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
474 $args = "" unless defined $args;
475 dbg("aliased cmd: $cmd $args") if isdbg('command');
478 # first expand out the entry to a command
479 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
480 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
483 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
485 my $package = find_cmd_name($path, $fcmd);
490 dbg("package: $package") if isdbg('command');
491 eval { @ans = &$package($self, $args) };
492 return (DXDebug::shortmess($@)) if $@;
495 dbg("cmd: $cmd not found") if isdbg('command');
496 if (++$self->{errors} > $maxerrors) {
497 $self->send($self->msg('e26'));
501 return ($self->msg('e1'));
508 delete $self->{errors};
510 if (++$self->{errors} > $maxerrors) {
511 $self->send($self->msg('e26'));
516 return map {s/([^\s])\s+$/$1/; $_} @ans;
520 # This is called from inside the main cluster processing loop and is used
521 # for despatching commands that are doing some long processing job
526 my @dxchan = DXChannel::get_all();
529 foreach $dxchan (@dxchan) {
530 next if $dxchan->sort ne 'U';
532 # send a outstanding message prompt if required
533 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
534 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
535 $dxchan->lastmsgpoll($t);
538 # send a prompt if no activity out on this channel
539 if ($t >= $dxchan->t + $main::user_interval) {
540 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
545 while (my ($k, $v) = each %nothereslug) {
546 if ($main::systime >= $v + 300) {
547 delete $nothereslug{$k};
555 # finish up a user context
560 my $call = $self->call;
562 return if $self->{disconnecting}++;
564 delete $self->{senddbg};
566 my $uref = Route::User::get($call);
569 @rout = $main::routeroot->del_user($uref);
570 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
572 # issue a pc17 to everybody interested
573 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
575 confess "trying to disconnect a non existant user $call";
578 # I was the last node visited
579 $self->user->node($main::mycall);
581 # send info to all logged in thingies
582 $self->tell_login('logoutu');
583 $self->tell_buddies('logoutb');
585 LogDbg('DXCommand', "$call disconnected");
587 $self->SUPER::disconnect;
591 # short cut to output a prompt
598 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
600 my $call = $self->call;
601 my $date = cldate($main::systime);
602 my $time = ztime($main::systime);
603 my $prompt = $self->{prompt} || $self->msg('pr');
605 $call = "($call)" unless $self->here;
606 $prompt =~ s/\%C/$call/g;
607 $prompt =~ s/\%D/$date/g;
608 $prompt =~ s/\%T/$time/g;
609 $prompt =~ s/\%M/$main::mycall/g;
611 $self->send($prompt);
614 # broadcast a message to all users [except those mentioned after buffer]
617 my $pkg = shift; # ignored
618 my $s = shift; # the line to be rebroadcast
620 foreach my $dxchan (DXChannel::get_all()) {
621 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
622 next if grep $dxchan == $_, @_;
623 $dxchan->send($s); # send it
627 # gimme all the users
630 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
633 # run a script for this user
637 my $silent = shift || 0;
642 # search for the command in the cache of short->long form commands
647 my ($path, $short_cmd, $suffix) = @_;
650 # commands are lower case
651 $short_cmd = lc $short_cmd;
652 dbg("command: $path $short_cmd\n") if isdbg('command');
654 # do some checking for funny characters
655 return () if $short_cmd =~ /\/$/;
657 # return immediately if we have it
658 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
659 if ($apath && $acmd) {
660 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
661 return ($apath, $acmd);
665 my @parts = split '/', $short_cmd;
669 while (my $p = shift @parts) {
670 opendir(D, $curdir) or confess "can't open $curdir $!";
674 # if this isn't the last part
677 foreach my $l (sort @ls) {
679 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
680 dbg("got dir: $curdir/$l\n") if isdbg('command');
687 # only proceed if we find the directory asked for
688 return () unless $found;
690 foreach my $l (sort @ls) {
692 next unless $l =~ /\.$suffix$/;
693 if ($p eq substr($l, 0, length $p)) {
694 $l =~ s/\.$suffix$//;
695 $dirfn = "" unless $dirfn;
696 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
697 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
698 return ($path, "$dirfn$l");
707 # clear the command name cache
713 undef *{$_} unless /cmd_cache/;
714 dbg("Undefining cmd $_") if isdbg('command');
721 # the persistant execution of things from the command directories
724 # This allows perl programs to call functions dynamically
726 # This has been nicked directly from the perlembed pages
729 #require Devel::Symdump;
731 sub valid_package_name {
733 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
736 return "cmd_$string";
740 # this bit of magic finds a command in the offered directory
744 my $package = valid_package_name($cmdname);
745 my $filename = "$path/$cmdname.pl";
746 my $mtime = -M $filename;
748 # return if we can't find it
750 unless (defined $mtime) {
751 $errstr = DXM::msg('e1');
755 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
756 #we have compiled this subroutine already,
757 #it has not been updated on disk, nothing left to do
758 #print STDERR "already compiled $package->handler\n";
762 my $sub = readfilestr($filename);
764 $errstr = "Syserr: can't open '$filename' $!";
768 #wrap the code into a subroutine inside our unique package
769 my $eval = qq( sub $package { $sub } );
772 my @list = split /\n/, $eval;
775 dbg($_ . "\n") if isdbg('eval');
779 # get rid of any existing sub and try to compile the new one
782 if (exists $Cache{$package}) {
783 dbg("Redefining $package") if isdbg('command');
786 dbg("Defining $package") if isdbg('command');
790 $Cache{$package} = {mtime => $mtime };
802 $self->SUPER::send(dd(['cmd',$_]));
805 $self->SUPER::send(@_);
811 my ($self, $let, $buf) = @_;
812 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
813 if ($self->{enhanced}) {
814 $self->send_later($let, $buf);
823 # send a talk message here
826 my ($self, $from, $to, $via, $line) = @_;
827 $line =~ s/\\5E/\^/g;
830 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
832 $self->local_send('T', "$to de $from: $line");
835 Log('talk', $to, $from, $via?$via:$main::mycall, $line);
836 # send a 'not here' message if required
837 unless ($self->{here} && $from ne $to) {
838 my $key = "$to$from";
839 unless (exists $nothereslug{$key}) {
841 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
842 my $name = $self->user->name || $to;
843 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
844 $nothereslug{$key} = $main::systime;
845 $dxchan->talk($to, $from, undef, $s);
862 if (!$self->{ann_talk} && $to ne $self->{call}) {
863 my $call = AnnTalk::is_talk_candidate($_[0], $text);
867 if ($self->{annfilter}) {
868 ($filter, $hops) = $self->{annfilter}->it(@_ );
869 return unless $filter;
872 unless ($self->{ann}) {
873 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
875 return if $target eq 'SYSOP' && $self->{priv} < 5;
878 $buf = dd(['ann', $to, $target, $text, @_])
880 $buf = "$to$target de $_[0]: $text";
882 $buf .= "\a\a" if $self->{beep};
884 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
898 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
900 $text =~ s/^\#\d+ //;
903 $buf = dd(['chat', $to, $target, $text, @_])
905 $buf = "$target de $_[0]: $text";
907 $buf .= "\a\a" if $self->{beep};
909 $self->local_send('C', $buf);
916 my $t = ztime($_[2]);
918 my $clth = $self->{consort} eq 'local' ? 29 : 30;
919 my $comment = substr $_[3], 0, $clth;
920 $comment .= ' ' x ($clth - length($comment));
921 if ($self->{user}->wantgrid) {
922 my $ref = DXUser->get_current($_[4]);
924 $loc = $ref->qra || '';
925 $loc = ' ' . substr($loc, 0, 4) if $loc;
929 if ($self->{user}->wantdxitu) {
930 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
931 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
932 } elsif ($self->{user}->wantdxcq) {
933 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
934 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
935 } elsif ($self->{user}->wantusstate) {
936 $loc = ' ' . $_[13] if $_[13];
937 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
940 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
949 return unless $self->{dx};
953 if ($self->{spotsfilter}) {
954 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
955 return unless $filter;
958 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
961 if ($self->{ve7cc}) {
962 $buf = VE7CC::dx_spot($self, @_);
963 } elsif ($self->{gtk}) {
966 my $ref = DXUser->get_current($_[4]);
969 $byloc = substr($byloc, 0, 4) if $byloc;
973 $spot =~ s|/\w{1,4}$||;
974 $ref = DXUser->get_current($spot);
977 $dxloc = substr($dxloc, 0, 4) if $dxloc;
979 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
982 $buf = $self->format_dx_spot(@_);
983 $buf .= "\a\a" if $self->{beep};
987 $self->local_send('X', $buf);
997 return unless $self->{wwv};
999 if ($self->{wwvfilter}) {
1000 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1001 return unless $filter;
1006 $buf = dd(['wwv', @_])
1008 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1009 $buf .= "\a\a" if $self->{beep};
1012 $self->local_send('V', $buf);
1019 my $isolate = shift;
1020 my ($filter, $hops);
1022 return unless $self->{wcy};
1024 if ($self->{wcyfilter}) {
1025 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1026 return unless $filter;
1031 $buf = dd(['wcy', @_])
1033 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1034 $buf .= "\a\a" if $self->{beep};
1036 $self->local_send('Y', $buf);
1039 # broadcast debug stuff to all interested parties
1042 my $s = shift; # the line to be rebroadcast
1044 foreach my $dxchan (DXChannel::get_all) {
1045 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1046 if ($dxchan->{gtk}) {
1047 $dxchan->send_later('L', dd(['db', $s]));
1049 $dxchan->send_later('L', $s);
1060 if ($self->state eq 'enterbody') {
1061 my $loc = $self->{loc} || confess "local var gone missing" ;
1062 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1064 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1066 $self->state('prompt');
1067 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1068 push @out, $self->msg('m10');
1069 delete $loc->{lines};
1070 delete $self->{loc};
1072 $self->state('prompt');
1074 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1075 # i.e. it ain't and end or abort, therefore store the line
1078 confess "Invalid state $self->{state}";
1083 sub store_startup_script
1086 my $loc = $self->{loc} || confess "local var gone missing" ;
1088 my $call = $loc->{call} || confess "callsign gone missing";
1089 confess "lines array gone missing" unless ref $loc->{lines};
1090 my $r = Script::store($call, $loc->{lines});
1093 push @out, $self->msg('m19', $call, $r);
1095 push @out, $self->msg('m20', $call);
1098 push @out, "error opening startup script $call $!";
1103 # Import any commands contained in any files in import_cmd directory
1105 # If the filename has a recogisable callsign as some delimited part
1106 # of it, then this is the user the command will be run as.
1110 # are there any to do in this directory?
1111 return unless -d $cmdimportdir;
1112 unless (opendir(DIR, $cmdimportdir)) {
1113 LogDbg('err', "can\'t open $cmdimportdir $!");
1117 my @names = readdir(DIR);
1120 foreach $name (@names) {
1121 next if $name =~ /^\./;
1123 my $s = Script->new($name, $cmdimportdir);
1125 LogDbg('DXCommand', "Run import cmd file $name");
1126 my @cat = split /[^A-Za-z0-9]+/, $name;
1127 my ($call) = grep {is_callsign(uc $_)} @cat;
1128 $call ||= $main::mycall;
1133 $s->inscript(0); # switch off script checks
1135 if ($call eq $main::mycall) {
1136 @out = $s->run($main::me, 1);
1138 my $dxchan = DXChannel::get($call);
1140 @out = $s->run($dxchan, 1);
1142 my $u = DXUser->get($call);
1144 $dxchan = $main::me;
1145 my $old = $dxchan->{call};
1146 my $priv = $dxchan->{priv};
1147 my $user = $dxchan->{user};
1148 $dxchan->{call} = $call;
1149 $dxchan->{priv} = $u->priv;
1150 $dxchan->{user} = $u;
1151 @out = $s->run($dxchan, 1);
1152 $dxchan->{call} = $call;
1153 $dxchan->{priv} = $priv;
1154 $dxchan->{user} = $user;
1156 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1162 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1165 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1166 unlink "$cmdimportdir/$name";