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 %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 $maxbadcount = 3; # no of bad words allowed before disconnection
51 $msgpolltime = 3600; # the time between polls for new messages
52 $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts
53 # this does not exist as default, you need to create it manually
57 # obtain a new connection this is derived from dxchannel
62 my $self = DXChannel::alloc(@_);
64 # routing, this must go out here to prevent race condx
67 # my @rout = $main::routeroot->add_user($call, Route::here(1));
68 DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->{conn}->peerhost], );
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) unless $DXProt::pc92_slug_changes;
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 (who wanted 2???) Note registration *could* be used even when reqreg == 0
128 if ($main::reqreg == 2) {
129 $self->{registered} = !$user->registered;
131 $self->{registered} = $user->registered;
134 # establish slug queue, if required
135 $self->{sluggedpcs} = [];
136 $self->{isslugged} = $DXProt::pc92_slug_changes + $DXProt::last_pc92_slug + 5 if $DXProt::pc92_slug_changes;
137 $self->{isslugged} = 0 if $self->{priv} > 0 || $user->registered || $user->homenode eq $main::mycall;
139 # send the relevant MOTD
142 # sort out privilege reduction
143 $self->{priv} = 0 unless $self->{hostname} eq '127.0.0.1' || $self->{hostname} eq '::1' || $self->conn->{usedpasswd};
147 $nossid =~ s/-\d+$//;
149 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
150 || Filter::read_in('spots', $nossid, 0)
151 || Filter::read_in('spots', 'user_default', 0);
152 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
153 || Filter::read_in('wwv', $nossid, 0)
154 || Filter::read_in('wwv', 'user_default', 0);
155 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
156 || Filter::read_in('wcy', $nossid, 0)
157 || Filter::read_in('wcy', 'user_default', 0);
158 $self->{annfilter} = Filter::read_in('ann', $call, 0)
159 || Filter::read_in('ann', $nossid, 0)
160 || Filter::read_in('ann', 'user_default', 0) ;
162 # clean up qra locators
163 my $qra = $user->qra;
164 $qra = undef if ($qra && !DXBearing::is_qra($qra));
166 my $lat = $user->lat;
167 my $long = $user->long;
168 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
172 my $echo = $user->wantecho;
174 $self->send_now('E', "0");
175 $self->send($self->msg('echow'));
176 $self->conn->echo($echo) if $self->conn->can('echo');
179 $self->tell_login('loginu');
180 $self->tell_buddies('loginb');
182 # do we need to send a forward/opernam?
183 my $lastoper = $user->lastoper || 0;
184 my $homenode = $user->homenode || "";
185 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
186 run_cmd($main::me, "forward/opernam $call");
187 $user->lastoper($main::systime + ((int rand(10)) * 86400));
190 # run a script send the output to the punter
191 my $script = new Script(lc $call) || new Script('user_default');
192 $script->run($self) if $script;
195 my $info = Route::cluster();
196 $self->send("Cluster:$info");
198 # send prompts for qth, name and things
199 $self->send($self->msg('namee1')) if !$user->name;
200 $self->send($self->msg('qthe1')) if !$user->qth;
201 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
202 $self->send($self->msg('hnodee1')) if !$user->qth;
203 $self->send($self->msg('m9')) if DXMsg::for_me($call);
205 # send out any buddy messages for other people that are online
206 foreach my $call (@{$user->buddies}) {
207 my $ref = Route::User::get($call);
209 foreach my $node ($ref->parents) {
210 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
215 $self->lastmsgpoll($main::systime);
220 # This is the normal command prompt driver
229 # save this for them's that need it
230 my $rawline = $cmdline;
232 # remove leading and trailing spaces
233 $cmdline =~ s/^\s*(.*)\s*$/$1/;
235 if ($self->{state} eq 'page') {
236 my $i = $self->{pagelth};
237 my $ref = $self->{pagedata};
240 # abort if we get a line starting in with a
241 if ($cmdline =~ /^a/io) {
246 # send a tranche of data
247 while ($i-- > 0 && @$ref) {
248 my $line = shift @$ref;
249 $line =~ s/\s+$//o; # why am having to do this?
253 # reset state if none or else chuck out an intermediate prompt
255 $tot -= $self->{pagelth};
256 $self->send($self->msg('page', $tot));
258 $self->state('prompt');
260 } elsif ($self->{state} eq 'sysop') {
261 my $passwd = $self->{user}->passwd;
263 my @pw = grep {$_ !~ /\s/} split //, $passwd;
264 my @l = @{$self->{passwd}};
265 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
266 if ($cmdline =~ /$str/) {
267 $self->{priv} = $self->{user}->priv;
269 $self->send($self->msg('sorry'));
272 $self->send($self->msg('sorry'));
274 $self->state('prompt');
275 } elsif ($self->{state} eq 'passwd') {
276 my $passwd = $self->{user}->passwd;
277 if ($passwd && $cmdline eq $passwd) {
278 $self->send($self->msg('pw1'));
279 $self->state('passwd1');
281 $self->conn->{echo} = $self->conn->{decho};
282 delete $self->conn->{decho};
283 $self->send($self->msg('sorry'));
284 $self->state('prompt');
286 } elsif ($self->{state} eq 'passwd1') {
287 $self->{passwd} = $cmdline;
288 $self->send($self->msg('pw2'));
289 $self->state('passwd2');
290 } elsif ($self->{state} eq 'passwd2') {
291 if ($cmdline eq $self->{passwd}) {
292 $self->{user}->passwd($cmdline);
293 $self->send($self->msg('pw3'));
295 $self->send($self->msg('pw4'));
297 $self->conn->{echo} = $self->conn->{decho};
298 delete $self->conn->{decho};
299 $self->state('prompt');
300 } elsif ($self->{state} eq 'talk' || $self->{state} eq 'chat') {
301 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
302 for (@{$self->{talklist}}) {
303 if ($self->{state} eq 'talk') {
304 $self->send_talks($_, $self->msg('talkend'));
306 $self->local_send('C', $self->msg('chatend', $_));
309 $self->state('prompt');
310 delete $self->{talklist};
311 } elsif ($cmdline =~ m|^/+\w+|) {
313 my $sendit = $cmdline =~ s|^/+||;
314 my @in = $self->run_cmd($cmdline);
315 $self->send_ans(@in);
316 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
317 foreach my $l (@in) {
319 if (@bad = BadWords::check($l)) {
320 $self->badcount(($self->badcount||0) + @bad);
321 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
323 for (@{$self->{talklist}}) {
324 if ($self->{state} eq 'talk') {
325 $self->send_talks($_, $l);
327 send_chats($self, $_, $l)
333 $self->send($self->{state} eq 'talk' ? $self->talk_prompt : $self->chat_prompt);
334 } elsif ($self->{talklist} && @{$self->{talklist}}) {
335 # send what has been said to whoever is in this person's talk list
337 if (@bad = BadWords::check($cmdline)) {
338 $self->badcount(($self->badcount||0) + @bad);
339 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
341 for (@{$self->{talklist}}) {
342 if ($self->{state} eq 'talk') {
343 $self->send_talks($_, $rawline);
345 send_chats($self, $_, $rawline);
349 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
350 $self->send($self->chat_prompt) if $self->{state} eq 'chat';
353 $self->state('prompt');
355 } elsif (my $func = $self->{func}) {
358 if (ref $self->{edit}) {
359 eval { @ans = $self->{edit}->$func($self, $rawline)};
361 eval { @ans = &{$self->{func}}($self, $rawline) };
364 $self->send_ans("Syserr: on stored func $self->{func}", $@);
365 delete $self->{func};
366 $self->state('prompt');
369 $self->send_ans(@ans);
371 $self->send_ans(run_cmd($self, $cmdline));
374 # check for excessive swearing
375 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
376 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
381 # send a prompt only if we are in a prompt state
382 $self->prompt() if $self->{state} =~ /^prompt/o;
385 # send out the talk messages taking into account vias and connectivity
388 my ($self, $ent, $line) = @_;
390 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
391 $to = $ent unless $to;
392 my $call = $via && $via ne '*' ? $via : $to;
393 my $clref = Route::get($call);
394 my $dxchan = $clref->dxchan if $clref;
396 $dxchan->talk($self->{call}, $to, undef, $line);
398 $self->send($self->msg('disc2', $via ? $via : $to));
399 my @l = grep { $_ ne $ent } @{$self->{talklist}};
401 $self->{talklist} = \@l;
403 delete $self->{talklist};
404 $self->state('prompt');
415 my $msgid = DXProt::nextchatmsgid();
416 $text = "#$msgid $text";
417 $main::me->normal(DXProt::pc93($target, $self->{call}, undef, $text));
425 for (@{$self->{talklist}}) {
426 my ($to, $via) = /(\S+)>(\S+)/;
430 return $self->msg($prompt, join(',', @call));
436 return $self->special_prompt('talkprompt');
442 return $self->special_prompt('chatprompt');
446 # send a load of stuff to a command user with page prompting
454 if ($self->{pagelth} && @_ > $self->{pagelth}) {
456 for ($i = $self->{pagelth}; $i-- > 0; ) {
458 $line =~ s/\s+$//o; # why am having to do this?
461 $self->{pagedata} = [ @_ ];
462 $self->state('page');
463 $self->send($self->msg('page', scalar @_));
476 # this is the thing that runs the command, it is done like this for the
477 # benefit of remote command execution
483 my $user = $self->{user};
484 my $call = $self->{call};
488 return () if length $cmdline == 0;
490 # split the command line up into parts, the first part is the command
491 my ($cmd, $args) = split /\s+/, $cmdline, 2;
492 $args = "" unless defined $args;
497 if ($cmd =~ m|^/| || $cmd =~ m|[^-?\w/]|) {
498 LogDbg('DXCommand', "cmd: invalid characters in '$cmd'");
499 return $self->_error_out('e1');
502 # strip out // on command only
507 dbg("cmd: $cmd") if isdbg('command');
509 # alias it if possible
510 my $acmd = CmdAlias::get_cmd($cmd);
512 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
513 $args = "" unless defined $args;
514 dbg("cmd: aliased $cmd $args") if isdbg('command');
517 # first expand out the entry to a command
518 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
519 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
522 dbg("cmd: path $cmd cmd: $fcmd") if isdbg('command');
524 my $package = find_cmd_name($path, $fcmd);
527 if ($package && $self->can("${package}::handle")) {
529 dbg("cmd: package $package") if isdbg('command');
530 eval { @ans = &{"${package}::handle"}($self, $args) };
531 return (DXDebug::shortmess($@)) if $@;
533 dbg("cmd: $package not present") if isdbg('command');
534 return $self->_error_out('e1');
537 dbg("cmd: $cmd not found") if isdbg('command');
538 return $self->_error_out('e1');
544 delete $self->{errors};
546 if (++$self->{errors} > $DXChannel::maxerrors) {
547 $self->send($self->msg('e26'));
552 return map {s/([^\s])\s+$/$1/; $_} @ans;
556 # This is called from inside the main cluster processing loop and is used
557 # for despatching commands that are doing some long processing job
562 my @dxchan = DXChannel::get_all();
565 foreach $dxchan (@dxchan) {
566 next if $dxchan->is_user;
568 # send a outstanding message prompt if required
569 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
570 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
571 $dxchan->lastmsgpoll($t);
574 # send a prompt if no activity out on this channel
575 if ($t >= $dxchan->t + $main::user_interval) {
576 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
580 if ($dxchan->{isslugged} && $main::systime > $dxchan->{isslugged}) {
581 foreach my $ref (@{$dxchan->{sluggedpcs}}) {
582 if ($ref->[0] == 61) {
583 Spot::add(@{$ref->[2]});
584 DXProt::send_dx_spot($dxchan, $ref->[1], @{$ref->[2]});
588 $dxchan->{isslugged} = 0;
589 $dxchan->{sluggedpcs} = [];
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
763 for my $k (keys %Cache) {
764 unless ($k =~ /cmd_cache/) {
765 dbg("Undefining cmd $k") if isdbg('command');
766 undef $DXCommandmode::{"${k}::"};
770 %Cache = ( cmd_clear_cmd_cache => $Cache{cmd_clear_cmd_cache} );
774 # the persistant execution of things from the command directories
777 # This allows perl programs to call functions dynamically
779 # This has been nicked directly from the perlembed pages
781 #require Devel::Symdump;
783 sub valid_package_name {
785 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
788 return "cmd_$string";
792 # this bit of magic finds a command in the offered directory
796 my $package = valid_package_name($cmdname);
797 my $filename = "$path/$cmdname.pl";
798 my $mtime = -M $filename;
800 # return if we can't find it
802 unless (defined $mtime) {
803 $errstr = DXM::msg('e1');
807 if(exists $Cache{$package} && exists $Cache{$package}->{mtime} && $Cache{$package}->{mtime} <= $mtime) {
808 #we have compiled this subroutine already,
809 #it has not been updated on disk, nothing left to do
810 #print STDERR "already compiled $package->handler\n";
814 my $sub = readfilestr($filename);
816 $errstr = "Syserr: can't open '$filename' $!";
820 #wrap the code into a subroutine inside our unique package
821 my $eval = qq(package DXCommandmode::$package; use POSIX qw{:math_h}; use DXLog; use DXDebug; use DXUser; use DXUtil; our \@ISA = qw{DXCommandmode}; );
824 if ($sub =~ m|\s*sub\s+handle\n|) {
827 $eval .= qq(sub handle { $sub });
831 my @list = split /\n/, $eval;
834 dbg($_ . "\n") if isdbg('eval');
838 # get rid of any existing sub and try to compile the new one
841 if (exists $Cache{$package}) {
842 dbg("find_cmd_name: Redefining $package") if isdbg('command');
843 undef $DXCommandmode::{"${package}::"};
844 delete $Cache{$package};
846 dbg("find_cmd_name: Defining $package") if isdbg('command');
851 $Cache{$package} = {mtime => $mtime } unless $@;
854 return "DXCommandmode::$package";
862 $self->SUPER::send(dd(['cmd',$_]));
865 $self->SUPER::send(@_);
871 my ($self, $let, $buf) = @_;
872 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk' || $self->{state} eq 'chat') {
873 if ($self->{enhanced}) {
874 $self->send_later($let, $buf);
883 # send a talk message here
886 my ($self, $from, $to, $via, $line, $onode) = @_;
887 $line =~ s/\\5E/\^/g;
890 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
892 $self->local_send('T', "$to de $from: $line");
895 Log('talk', $to, $from, '<' . ($onode || '*'), $line);
896 # send a 'not here' message if required
897 unless ($self->{here} && $from ne $to) {
898 my $key = "$to$from";
899 unless (exists $nothereslug{$key}) {
901 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
902 my $name = $self->user->name || $to;
903 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
904 $nothereslug{$key} = $main::systime;
905 $dxchan->talk($to, $from, undef, $s);
922 if (!$self->{ann_talk} && $to ne $self->{call}) {
923 my $call = AnnTalk::is_talk_candidate($_[0], $text);
927 if ($self->{annfilter}) {
928 ($filter, $hops) = $self->{annfilter}->it(@_ );
929 return unless $filter;
932 unless ($self->{ann}) {
933 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
935 return if $target eq 'SYSOP' && $self->{priv} < 5;
938 $buf = dd(['ann', $to, $target, $text, @_])
940 $buf = "$to$target de $_[0]: $text";
942 $buf .= "\a\a" if $self->{beep};
944 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
958 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
960 $text =~ s/^\#\d+ //;
963 $buf = dd(['chat', $to, $target, $text, @_])
965 $buf = "$target de $_[0]: $text";
967 $buf .= "\a\a" if $self->{beep};
969 $self->local_send('C', $buf);
976 my $t = ztime($_[2]);
978 my ($slot1, $slot2) = ('', '');
980 my $clth = 30 + $self->{width} - 80; # allow comment to grow according the screen width
981 my $comment = substr (($_[3] || ''), 0, $clth);
982 $comment =~ s/\t/ /g;
983 $comment .= ' ' x ($clth - (length($comment)));
985 if (!$slot1 && $self->{user}->wantgrid) {
986 my $ref = DXUser::get_current($_[1]);
987 if ($ref && $ref->qra) {
988 $slot1 = ' ' . substr($ref->qra, 0, 4);
991 if (!$slot1 && $self->{user}->wantusstate) {
992 $slot1 = " $_[12]" if $_[12];
995 if ($self->{user}->wantdxitu) {
996 $slot1 = sprintf(" %2d", $_[8]) if defined $_[8];
997 } elsif ($self->{user}->wantdxcq) {
998 $slot1 = sprintf(" %2d", $_[9]) if defined $_[9];
1001 $comment = substr($comment, 0, $clth-length($slot1)) . $slot1 if $slot1;
1003 if (!$slot2 && $self->{user}->wantgrid) {
1005 $origin =~ s/-#$//; # sigh......
1006 my $ref = DXUser::get_current($origin);
1007 if ($ref && $ref->qra) {
1008 $slot2 = ' ' . substr($ref->qra, 0, 4);
1011 if (!$slot2 && $self->{user}->wantusstate) {
1012 $slot2 = " $_[13]" if $_[13];
1015 if ($self->{user}->wantdxitu) {
1016 $slot2 = sprintf(" %2d", $_[10]) if defined $_[10];
1017 } elsif ($self->{user}->wantdxcq) {
1018 $slot2 = sprintf(" %2d", $_[11]) if defined $_[11];
1022 return sprintf "DX de %-8.8s%10.1f %-12.12s %-s $t$slot2", "$_[4]:", $_[0], $_[1], $comment;
1030 my $isolate = shift;
1031 return unless $self->{dx};
1033 my ($filter, $hops);
1035 if ($self->{spotsfilter}) {
1036 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
1037 return unless $filter;
1040 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
1043 if ($self->{ve7cc}) {
1044 $buf = VE7CC::dx_spot($self, @_);
1045 } elsif ($self->{gtk}) {
1046 my ($dxloc, $byloc);
1048 my $ref = DXUser::get_current($_[4]);
1051 $byloc = substr($byloc, 0, 4) if $byloc;
1055 $spot =~ s|/\w{1,4}$||;
1056 $ref = DXUser::get_current($spot);
1059 $dxloc = substr($dxloc, 0, 4) if $dxloc;
1061 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
1064 $buf = $self->format_dx_spot(@_);
1065 $buf .= "\a\a" if $self->{beep};
1069 $self->local_send('X', $buf);
1076 my $isolate = shift;
1077 my ($filter, $hops);
1079 return unless $self->{wwv};
1081 if ($self->{wwvfilter}) {
1082 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1083 return unless $filter;
1088 $buf = dd(['wwv', @_])
1090 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1091 $buf .= "\a\a" if $self->{beep};
1094 $self->local_send('V', $buf);
1101 my $isolate = shift;
1102 my ($filter, $hops);
1104 return unless $self->{wcy};
1106 if ($self->{wcyfilter}) {
1107 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1108 return unless $filter;
1113 $buf = dd(['wcy', @_])
1115 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1116 $buf .= "\a\a" if $self->{beep};
1118 $self->local_send('Y', $buf);
1121 # broadcast debug stuff to all interested parties
1124 my $s = shift; # the line to be rebroadcast
1126 foreach my $dxchan (DXChannel::get_all) {
1127 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1128 if ($dxchan->{gtk}) {
1129 $dxchan->send_later('L', dd(['db', $s]));
1131 $dxchan->send_later('L', $s);
1142 if ($self->state eq 'enterbody') {
1143 my $loc = $self->{loc} || confess "local var gone missing" ;
1144 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1146 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1148 $self->state('prompt');
1149 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1150 push @out, $self->msg('m10');
1151 delete $loc->{lines};
1152 delete $self->{loc};
1154 $self->state('prompt');
1156 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1157 # i.e. it ain't and end or abort, therefore store the line
1160 confess "Invalid state $self->{state}";
1165 sub store_startup_script
1168 my $loc = $self->{loc} || confess "local var gone missing" ;
1170 my $call = $loc->{call} || confess "callsign gone missing";
1171 confess "lines array gone missing" unless ref $loc->{lines};
1172 my $r = Script::store($call, $loc->{lines});
1175 push @out, $self->msg('m19', $call, $r);
1177 push @out, $self->msg('m20', $call);
1180 push @out, "error opening startup script $call $!";
1185 # Import any commands contained in any files in import_cmd directory
1187 # If the filename has a recogisable callsign as some delimited part
1188 # of it, then this is the user the command will be run as.
1192 # are there any to do in this directory?
1193 return unless -d $cmdimportdir;
1194 unless (opendir(DIR, $cmdimportdir)) {
1195 LogDbg('err', "can\'t open $cmdimportdir $!");
1199 my @names = readdir(DIR);
1202 foreach $name (@names) {
1203 next if $name =~ /^\./;
1205 my $s = Script->new($name, $cmdimportdir);
1207 LogDbg('DXCommand', "Run import cmd file $name");
1208 my @cat = split /[^A-Za-z0-9]+/, $name;
1209 my ($call) = grep {is_callsign(uc $_)} @cat;
1210 $call ||= $main::mycall;
1215 $s->inscript(0); # switch off script checks
1217 if ($call eq $main::mycall) {
1218 @out = $s->run($main::me, 1);
1220 my $dxchan = DXChannel::get($call);
1222 @out = $s->run($dxchan, 1);
1224 my $u = DXUser::get($call);
1226 $dxchan = $main::me;
1227 my $old = $dxchan->{call};
1228 my $priv = $dxchan->{priv};
1229 my $user = $dxchan->{user};
1230 $dxchan->{call} = $call;
1231 $dxchan->{priv} = $u->priv;
1232 $dxchan->{user} = $u;
1233 @out = $s->run($dxchan, 1);
1234 $dxchan->{call} = $old;
1235 $dxchan->{priv} = $priv;
1236 $dxchan->{user} = $user;
1238 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1244 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1247 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1248 unlink "$cmdimportdir/$name";
1253 sub print_find_reply
1255 my ($self, $node, $target, $flag, $ms) = @_;
1256 my $sort = $flag == 2 ? "External" : "Local";
1257 $self->send("$sort $target found at $node in $ms ms" );
1260 # send the most relevant motd
1266 unless ($self->registered) {
1267 $motd = "${main::motd}_nor_$self->{lang}";
1268 $motd = "${main::motd}_nor" unless -e $motd;
1270 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
1271 $motd = $main::motd unless $motd && -e $motd;
1272 if ($self->conn->ax25) {
1274 $motd = "${motd}_ax25" if -e "${motd}_ax25";
1276 $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25";
1279 $self->send_file($motd) if -e $motd;