Added set/prompt (and unset/prompt) command so that Stephan can fool some
[spider.git] / perl / DXCommandmode.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the user facing command mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXCommandmode;
11
12 use POSIX;
13
14 @ISA = qw(DXChannel);
15
16 use DXUtil;
17 use DXChannel;
18 use DXUser;
19 use DXVars;
20 use DXDebug;
21 use DXM;
22 use DXLog;
23 use DXLogPrint;
24 use DXBearing;
25 use CmdAlias;
26 use Filter;
27 use Minimuf;
28 use DXDb;
29 use AnnTalk;
30 use WCY;
31 use Sun;
32 use Internet;
33 use Script;
34
35
36 use strict;
37 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug $maxbadcount);
38
39 %Cache = ();                                    # cache of dynamically loaded routine's mod times
40 %cmd_cache = ();                                # cache of short names
41 $errstr = ();                                   # error string from eval
42 %aliases = ();                                  # aliases for (parts of) commands
43 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
44 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
45 $maxbadcount = 3;                               # no of bad words allowed before disconnection
46
47
48 use vars qw($VERSION $BRANCH);
49 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
50 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
51 $main::build += $VERSION;
52 $main::branch += $BRANCH;
53
54 #
55 # obtain a new connection this is derived from dxchannel
56 #
57
58 sub new 
59 {
60         my $self = DXChannel::alloc(@_);
61
62         # routing, this must go out here to prevent race condx
63         my $pkg = shift;
64         my $call = shift;
65         my @rout = $main::routeroot->add_user($call, Route::here(1));
66
67         # ALWAYS output the user
68         my $ref = Route::User::get($call);
69         DXProt::route_pc16($main::me, $main::routeroot, $ref) if $ref;
70
71         return $self;
72 }
73
74 # this is how a a connection starts, you get a hello message and the motd with
75 # possibly some other messages asking you to set various things up if you are
76 # new (or nearly new and slacking) user.
77
78 sub start
79
80         my ($self, $line, $sort) = @_;
81         my $user = $self->{user};
82         my $call = $self->{call};
83         my $name = $user->{name};
84         
85         # log it
86         my $host = $self->{conn}->{peerhost} || "unknown";
87         Log('DXCommand', "$call connected from $host");
88
89         $self->{name} = $name ? $name : $call;
90         $self->send($self->msg('l2',$self->{name}));
91         $self->state('prompt');         # a bit of room for further expansion, passwords etc
92         $self->{priv} = $user->priv || 0;
93         $self->{lang} = $user->lang || $main::lang || 'en';
94         $self->{pagelth} = $user->pagelth || 20;
95         ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
96         $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
97         $self->{consort} = $line;       # save the connection type
98         
99         # set some necessary flags on the user if they are connecting
100         $self->{beep} = $user->wantbeep;
101         $self->{ann} = $user->wantann;
102         $self->{wwv} = $user->wantwwv;
103         $self->{wcy} = $user->wantwcy;
104         $self->{talk} = $user->wanttalk;
105         $self->{wx} = $user->wantwx;
106         $self->{dx} = $user->wantdx;
107         $self->{logininfo} = $user->wantlogininfo;
108         $self->{ann_talk} = $user->wantann_talk;
109         $self->{here} = 1;
110         $self->{prompt} = $user->prompt if $user->prompt;
111
112         # sort out registration
113         if ($main::reqreg == 1) {
114                 $self->{registered} = $user->registered;
115         } elsif ($main::reqreg == 2) {
116                 $self->{registered} = !$user->registered;
117         } else {
118                 $self->{registered} = 1;
119         }
120
121
122         # decide which motd to send
123         my $motd = "${main::motd}_nor" unless $self->{registered};
124         $motd = $main::motd unless $motd && -e $motd;
125         $self->send_file($motd) if -e $motd;
126
127         # sort out privilege reduction
128         $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
129
130         # get the filters
131         $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'user_default', 0);
132         $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'user_default', 0);
133         $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'user_default', 0);
134         $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'user_default', 0) ;
135
136         # clean up qra locators
137         my $qra = $user->qra;
138         $qra = undef if ($qra && !DXBearing::is_qra($qra));
139         unless ($qra) {
140                 my $lat = $user->lat;
141                 my $long = $user->long;
142                 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);  
143         }
144
145         # decide on echo
146         my $echo = $user->wantecho;
147         unless ($echo) {
148                 $self->send_now('E', "0");
149                 $self->send($self->msg('echow'));
150                 $self->conn->echo($echo) if $self->conn->can('echo');
151         }
152         
153         $self->tell_login('loginu');
154         
155         # do we need to send a forward/opernam?
156         my $lastoper = $user->lastoper || 0;
157         my $homenode = $user->homenode || ""; 
158         if ($homenode eq $main::mycall && $lastoper + $DXUser::lastoperinterval < $main::systime) {
159                 run_cmd($main::me, "forward/opernam $call");
160                 $user->lastoper($main::systime);
161         }
162
163         # run a script send the output to the punter
164         my $script = new Script(lc $call) || new Script('user_default');
165         $script->run($self) if $script;
166
167         # send cluster info
168         my $info = Route::cluster();
169         $self->send("Cluster:$info");
170
171         # send prompts and things
172         $self->send($self->msg('namee1')) if !$user->name;
173         $self->send($self->msg('qthe1')) if !$user->qth;
174         $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
175         $self->send($self->msg('hnodee1')) if !$user->qth;
176         $self->send($self->msg('m9')) if DXMsg::for_me($call);
177         $self->prompt;
178 }
179
180 #
181 # This is the normal command prompt driver
182 #
183
184 sub normal
185 {
186         my $self = shift;
187         my $cmdline = shift;
188         my @ans;
189         
190         # remove leading and trailing spaces
191         $cmdline =~ s/^\s*(.*)\s*$/$1/;
192         
193         if ($self->{state} eq 'page') {
194                 my $i = $self->{pagelth};
195                 my $ref = $self->{pagedata};
196                 my $tot = @$ref;
197                 
198                 # abort if we get a line starting in with a
199                 if ($cmdline =~ /^a/io) {
200                         undef $ref;
201                         $i = 0;
202                 }
203         
204                 # send a tranche of data
205                 while ($i-- > 0 && @$ref) {
206                         my $line = shift @$ref;
207                         $line =~ s/\s+$//o;     # why am having to do this? 
208                         $self->send($line);
209                 }
210                 
211                 # reset state if none or else chuck out an intermediate prompt
212                 if ($ref && @$ref) {
213                         $tot -= $self->{pagelth};
214                         $self->send($self->msg('page', $tot));
215                 } else {
216                         $self->state('prompt');
217                 }
218         } elsif ($self->{state} eq 'sysop') {
219                 my $passwd = $self->{user}->passwd;
220                 if ($passwd) {
221                         my @pw = grep {$_ !~ /\s/} split //, $passwd;
222                         my @l = @{$self->{passwd}};
223                         my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
224                         if ($cmdline =~ /$str/) {
225                                 $self->{priv} = $self->{user}->priv;
226                         } else {
227                                 $self->send($self->msg('sorry'));
228                         }
229                 } else {
230                         $self->send($self->msg('sorry'));
231                 }
232                 $self->state('prompt');
233         } elsif ($self->{state} eq 'passwd') {
234                 my $passwd = $self->{user}->passwd;
235                 if ($passwd && $cmdline eq $passwd) {
236                         $self->send($self->msg('pw1'));
237                         $self->state('passwd1');
238                 } else {
239                         $self->conn->{echo} = $self->conn->{decho};
240                         delete $self->conn->{decho};
241                         $self->send($self->msg('sorry'));
242                         $self->state('prompt');
243                 }
244         } elsif ($self->{state} eq 'passwd1') {
245                 $self->{passwd} = $cmdline;
246                 $self->send($self->msg('pw2'));
247                 $self->state('passwd2');
248         } elsif ($self->{state} eq 'passwd2') {
249                 if ($cmdline eq $self->{passwd}) {
250                         $self->{user}->passwd($cmdline);
251                         $self->send($self->msg('pw3'));
252                 } else {
253                         $self->send($self->msg('pw4'));
254                 }
255                 $self->conn->{echo} = $self->conn->{decho};
256                 delete $self->conn->{decho};
257                 $self->state('prompt');
258         } elsif ($self->{state} eq 'talk') {
259                 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
260                         for (@{$self->{talklist}}) {
261                                 $self->send_talks($_,  $self->msg('talkend'));
262                         }
263                         $self->state('prompt');
264                         delete $self->{talklist};
265                 } elsif ($cmdline =~ m(^/\w+)) {
266                         $cmdline =~ s(^/)();
267                         $self->send_ans(run_cmd($self, $cmdline));
268                         $self->send($self->talk_prompt);
269                 } elsif ($self->{talklist} && @{$self->{talklist}}) {
270                         # send what has been said to whoever is in this person's talk list
271                         my @bad;
272                         if (@bad = BadWords::check($cmdline)) {
273                                 $self->badcount(($self->badcount||0) + @bad);
274                                 Log('DXCommand', "$self->{call} swore: $cmdline");
275                         } else {
276                                 for (@{$self->{talklist}}) {
277                                         $self->send_talks($_, $cmdline);
278                                 }
279                         }
280                         $self->send($self->talk_prompt) if $self->{state} eq 'talk';
281                 } else {
282                         # for safety
283                         $self->state('prompt');
284                 }
285         } elsif (my $func = $self->{func}) {
286                 no strict 'refs';
287                 my @ans;
288                 if (ref $self->{edit}) {
289                         eval { @ans = $self->{edit}->$func($self, $cmdline)};
290                 } else {
291                         eval {  @ans = &{$self->{func}}($self, $cmdline) };
292                 }
293                 if ($@) {
294                         $self->send_ans("Syserr: on stored func $self->{func}", $@);
295                         delete $self->{func};
296                         $self->state('prompt');
297                         undef $@;
298                 }
299                 $self->send_ans(@ans);
300         } else {
301                 $self->send_ans(run_cmd($self, $cmdline));
302         } 
303
304         # check for excessive swearing
305         if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
306                 Log('DXCommand', "$self->{call} logged out for excessive swearing");
307                 $self->disconnect;
308                 return;
309         }
310
311         # send a prompt only if we are in a prompt state
312         $self->prompt() if $self->{state} =~ /^prompt/o;
313 }
314
315 # send out the talk messages taking into account vias and connectivity
316 sub send_talks
317 {
318         my ($self, $ent, $line) = @_;
319         
320         my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
321         $to = $ent unless $to;
322         my $call = $via ? $via : $to;
323         my $clref = Route::get($call);
324         my $dxchan = $clref->dxchan if $clref;
325         if ($dxchan) {
326                 $dxchan->talk($self->{call}, $to, $via, $line);
327         } else {
328                 $self->send($self->msg('disc2', $via ? $via : $to));
329                 my @l = grep { $_ ne $ent } @{$self->{talklist}};
330                 if (@l) {
331                         $self->{talklist} = \@l;
332                 } else {
333                         delete $self->{talklist};
334                         $self->state('prompt');
335                 }
336         }
337 }
338
339 sub talk_prompt
340 {
341         my $self = shift;
342         my @call;
343         for (@{$self->{talklist}}) {
344                 my ($to, $via) = /(\S+)>(\S+)/;
345                 $to = $_ unless $to;
346                 push @call, $to;
347         }
348         return $self->msg('talkprompt', join(',', @call));
349 }
350
351 #
352 # send a load of stuff to a command user with page prompting
353 # and stuff
354 #
355
356 sub send_ans
357 {
358         my $self = shift;
359         
360         if ($self->{pagelth} && @_ > $self->{pagelth}) {
361                 my $i;
362                 for ($i = $self->{pagelth}; $i-- > 0; ) {
363                         my $line = shift @_;
364                         $line =~ s/\s+$//o;     # why am having to do this? 
365                         $self->send($line);
366                 }
367                 $self->{pagedata} =  [ @_ ];
368                 $self->state('page');
369                 $self->send($self->msg('page', scalar @_));
370         } else {
371                 for (@_) {
372                         if (defined $_) {
373                                 $self->send($_);
374                         } else {
375                                 $self->send('');
376                         }
377                 }
378         } 
379 }
380
381 # this is the thing that runs the command, it is done like this for the 
382 # benefit of remote command execution
383 #
384
385 sub run_cmd
386 {
387         my $self = shift;
388         my $user = $self->{user};
389         my $call = $self->{call};
390         my $cmdline = shift;
391         my @ans;
392         
393
394         return () if length $cmdline == 0;
395                 
396         # strip out //
397         $cmdline =~ s|//|/|og;
398                 
399         # split the command line up into parts, the first part is the command
400         my ($cmd, $args) = split /\s+/, $cmdline, 2;
401         $args = "" unless defined $args;
402                 
403         if ($cmd) {
404                         
405                 my ($path, $fcmd);
406                         
407                 dbg("cmd: $cmd") if isdbg('command');
408                         
409                 # alias it if possible
410                 my $acmd = CmdAlias::get_cmd($cmd);
411                 if ($acmd) {
412                         ($cmd, $args) = split /\s+/, "$acmd $args", 2;
413                         $args = "" unless defined $args;
414                         dbg("aliased cmd: $cmd $args") if isdbg('command');
415                 }
416                         
417                 # first expand out the entry to a command
418                 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
419                 ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
420
421                 if ($path && $cmd) {
422                         dbg("path: $cmd cmd: $fcmd") if isdbg('command');
423                         
424                         my $package = find_cmd_name($path, $fcmd);
425                         return ($@) if $@;
426                                 
427                         if ($package) {
428                                 no strict 'refs';
429                                 dbg("package: $package") if isdbg('command');
430                                 eval { @ans = &$package($self, $args) };
431                                 return (DXDebug::shortmess($@)) if $@;
432                         }
433                 } else {
434                         dbg("cmd: $cmd not found") if isdbg('command');
435                         if (++$self->{errors} > $maxerrors) {
436                                 $self->send($self->msg('e26'));
437                                 $self->disconnect;
438                                 return ();
439                         } else {
440                                 return ($self->msg('e1'));
441                         }
442                 }
443         }
444         
445         my $ok = shift @ans;
446         if ($ok) {
447                 delete $self->{errors};
448         } else {
449                 if (++$self->{errors} > $maxerrors) {
450                         $self->send($self->msg('e26'));
451                         $self->disconnect;
452                         return ();
453                 }
454         }
455         return (@ans);
456 }
457
458 #
459 # This is called from inside the main cluster processing loop and is used
460 # for despatching commands that are doing some long processing job
461 #
462 sub process
463 {
464         my $t = time;
465         my @dxchan = DXChannel->get_all();
466         my $dxchan;
467         
468         foreach $dxchan (@dxchan) {
469                 next if $dxchan->sort ne 'U';  
470                 
471                 # send a prompt if no activity out on this channel
472                 if ($t >= $dxchan->t + $main::user_interval) {
473                         $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
474                         $dxchan->t($t);
475                 }
476         }
477
478         while (my ($k, $v) = each %nothereslug) {
479                 if ($main::systime >= $v + 300) {
480                         delete $nothereslug{$k};
481                 }
482         }
483 }
484
485 #
486 # finish up a user context
487 #
488 sub disconnect
489 {
490         my $self = shift;
491         my $call = $self->call;
492
493         return if $self->{disconnecting}++;
494
495         delete $self->{senddbg};
496
497         my $uref = Route::User::get($call);
498         my @rout;
499         if ($uref) {
500                 @rout = $main::routeroot->del_user($uref);
501                 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
502
503                 # issue a pc17 to everybody interested
504                 DXProt::route_pc17($main::me, $main::routeroot, $uref);
505         } else {
506                 confess "trying to disconnect a non existant user $call";
507         }
508
509         # I was the last node visited
510     $self->user->node($main::mycall);
511                 
512         # send info to all logged in thingies
513         $self->tell_login('logoutu');
514
515         Log('DXCommand', "$call disconnected");
516
517         $self->SUPER::disconnect;
518 }
519
520 #
521 # short cut to output a prompt
522 #
523
524 sub prompt
525 {
526         my $self = shift;
527         if ($self->{prompt}) {
528                 $self->send($self->{prompt});
529         } else {
530                 $self->send($self->msg($self->here ? 'pr' : 'pr2', $self->call, cldate($main::systime), ztime($main::systime)));
531         }
532 }
533
534 # broadcast a message to all users [except those mentioned after buffer]
535 sub broadcast
536 {
537         my $pkg = shift;                        # ignored
538         my $s = shift;                          # the line to be rebroadcast
539         
540     foreach my $dxchan (DXChannel->get_all()) {
541                 next unless $dxchan->{sort} eq 'U'; # only interested in user channels  
542                 next if grep $dxchan == $_, @_;
543                 $dxchan->send($s);                      # send it
544         }
545 }
546
547 # gimme all the users
548 sub get_all
549 {
550         return grep {$_->{sort} eq 'U'} DXChannel->get_all();
551 }
552
553 # run a script for this user
554 sub run_script
555 {
556         my $self = shift;
557         my $silent = shift || 0;
558         
559 }
560
561 #
562 # search for the command in the cache of short->long form commands
563 #
564
565 sub search
566 {
567         my ($path, $short_cmd, $suffix) = @_;
568         my ($apath, $acmd);
569         
570         # commands are lower case
571         $short_cmd = lc $short_cmd;
572         dbg("command: $path $short_cmd\n") if isdbg('command');
573
574         # do some checking for funny characters
575         return () if $short_cmd =~ /\/$/;
576
577         # return immediately if we have it
578         ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
579         if ($apath && $acmd) {
580                 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
581                 return ($apath, $acmd);
582         }
583         
584         # if not guess
585         my @parts = split '/', $short_cmd;
586         my $dirfn;
587         my $curdir = $path;
588         my $p;
589         my $i;
590         my @lparts;
591         
592         for ($i = 0; $i < @parts; $i++) {
593                 my  $p = $parts[$i];
594                 opendir(D, $curdir) or confess "can't open $curdir $!";
595                 my @ls = readdir D;
596                 closedir D;
597                 my $l;
598                 foreach $l (sort @ls) {
599                         next if $l =~ /^\./;
600                         if ($i < $#parts) {             # we are dealing with directories
601                                 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
602                                         dbg("got dir: $curdir/$l\n") if isdbg('command');
603                                         $dirfn .= "$l/";
604                                         $curdir .= "/$l";
605                                         last;
606                                 }
607                         } else {                        # we are dealing with commands
608                                 @lparts = split /\./, $l;                  
609                                 next if $lparts[$#lparts] ne $suffix;        # only look for .$suffix files
610                                 if ($p eq substr($l, 0, length $p)) {
611                                         pop @lparts; #  remove the suffix
612                                         $l = join '.', @lparts;
613                                         #                 chop $dirfn;               # remove trailing /
614                                         $dirfn = "" unless $dirfn;
615                                         $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
616                                         dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
617                                         return ($path, "$dirfn$l"); 
618                                 }
619                         }
620                 }
621         }
622         return ();  
623 }  
624
625 # clear the command name cache
626 sub clear_cmd_cache
627 {
628         no strict 'refs';
629         
630         for (keys %Cache) {
631                 undef *{$_};
632                 dbg("Undefining cmd $_") if isdbg('command');
633         }
634         %cmd_cache = ();
635         %Cache = ();
636 }
637
638 #
639 # the persistant execution of things from the command directories
640 #
641 #
642 # This allows perl programs to call functions dynamically
643
644 # This has been nicked directly from the perlembed pages
645 #
646
647 #require Devel::Symdump;  
648
649 sub valid_package_name {
650         my($string) = @_;
651         $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
652         
653         $string =~ s|/|_|g;
654         return "cmd_$string";
655 }
656
657
658 # this bit of magic finds a command in the offered directory
659 sub find_cmd_name {
660         my $path = shift;
661         my $cmdname = shift;
662         my $package = valid_package_name($cmdname);
663         my $filename = "$path/$cmdname.pl";
664         my $mtime = -M $filename;
665         
666         # return if we can't find it
667         $errstr = undef;
668         unless (defined $mtime) {
669                 $errstr = DXM::msg('e1');
670                 return undef;
671         }
672         
673         if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
674                 #we have compiled this subroutine already,
675                 #it has not been updated on disk, nothing left to do
676                 #print STDERR "already compiled $package->handler\n";
677                 ;
678         } else {
679
680                 my $sub = readfilestr($filename);
681                 unless ($sub) {
682                         $errstr = "Syserr: can't open '$filename' $!";
683                         return undef;
684                 };
685                 
686                 #wrap the code into a subroutine inside our unique package
687                 my $eval = qq( sub $package { $sub } );
688                 
689                 if (isdbg('eval')) {
690                         my @list = split /\n/, $eval;
691                         my $line;
692                         for (@list) {
693                                 dbg($_ . "\n") if isdbg('eval');
694                         }
695                 }
696                 
697                 # get rid of any existing sub and try to compile the new one
698                 no strict 'refs';
699
700                 if (exists $Cache{$package}) {
701                         dbg("Redefining $package") if isdbg('command');
702                         undef *$package;
703                 } else {
704                         dbg("Defining $package") if isdbg('command');
705                 }
706                 eval $eval;
707                 
708                 $Cache{$package} = {mtime => $mtime };
709             
710         }
711
712         return $package;
713 }
714
715 sub local_send
716 {
717         my ($self, $let, $buf) = @_;
718         if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
719                 if ($self->{enhanced}) {
720                         $self->send_later($let, $buf);
721                 } else {
722                         $self->send($buf);
723                 }
724         } else {
725                 $self->delay($buf);
726         }
727 }
728
729 # send a talk message here
730 sub talk
731 {
732         my ($self, $from, $to, $via, $line) = @_;
733         $line =~ s/\\5E/\^/g;
734         $self->local_send('T', "$to de $from: $line") if $self->{talk};
735         Log('talk', $to, $from, $via?$via:$main::mycall, $line);
736         # send a 'not here' message if required
737         unless ($self->{here} && $from ne $to) {
738                 my $key = "$to$from";
739                 unless (exists $nothereslug{$key}) {
740                         my ($ref, $dxchan);
741                         if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
742                                 my $name = $self->user->name || $to;
743                                 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
744                                 $nothereslug{$key} = $main::systime;
745                                 $dxchan->talk($to, $from, undef, $s);
746                         }
747                 }
748         }
749 }
750
751 # send an announce
752 sub announce
753 {
754         my $self = shift;
755         my $line = shift;
756         my $isolate = shift;
757         my $to = shift;
758         my $target = shift;
759         my $text = shift;
760         my ($filter, $hops);
761
762         if (!$self->{ann_talk} && $to ne $self->{call}) {
763                 my $call = AnnTalk::is_talk_candidate($_[0], $text);
764                 return if $call;
765         }
766
767         if ($self->{annfilter}) {
768                 ($filter, $hops) = $self->{annfilter}->it(@_ );
769                 return unless $filter;
770         }
771
772         unless ($self->{ann}) {
773                 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
774         }
775         return if $target eq 'SYSOP' && $self->{priv} < 5;
776         my $buf = "$to$target de $_[0]: $text";
777         $buf =~ s/\%5E/^/g;
778         $buf .= "\a\a" if $self->{beep};
779         $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
780 }
781
782 # send a dx spot
783 sub dx_spot
784 {
785         my $self = shift;
786         my $line = shift;
787         my $isolate = shift;
788         my ($filter, $hops);
789
790         return unless $self->{dx};
791         
792         if ($self->{spotsfilter}) {
793                 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
794                 return unless $filter;
795         }
796
797
798         my $t = ztime($_[2]);
799         my $ref = DXUser->get_current($_[4]);
800         my $loc = $ref->qra if $ref && $ref->qra && $self->{user}->wantgrid;
801         $loc = ' ' . substr($loc, 0, 4) if $loc;
802         $loc = "" unless $loc;
803         my $buf = sprintf "DX de %-7.7s%11.1f  %-12.12s %-*s $t$loc", "$_[4]:", $_[0], $_[1], $self->{consort} eq 'local' ? 29 : 30, $_[3];
804         $buf .= "\a\a" if $self->{beep};
805         $buf =~ s/\%5E/^/g;
806         $self->local_send('X', $buf);
807 }
808
809 sub wwv
810 {
811         my $self = shift;
812         my $line = shift;
813         my $isolate = shift;
814         my ($filter, $hops);
815
816         return unless $self->{wwv};
817         
818         if ($self->{wwvfilter}) {
819                 ($filter, $hops) = $self->{wwvfilter}->it(@_ );
820                 return unless $filter;
821         }
822
823         my $buf = "WWV de $_[6] <$_[1]>:   SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
824         $buf .= "\a\a" if $self->{beep};
825         $self->local_send('V', $buf);
826 }
827
828 sub wcy
829 {
830         my $self = shift;
831         my $line = shift;
832         my $isolate = shift;
833         my ($filter, $hops);
834
835         return unless $self->{wcy};
836         
837         if ($self->{wcyfilter}) {
838                 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
839                 return unless $filter;
840         }
841
842         my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
843         $buf .= "\a\a" if $self->{beep};
844         $self->local_send('Y', $buf);
845 }
846
847 # broadcast debug stuff to all interested parties
848 sub broadcast_debug
849 {
850         my $s = shift;                          # the line to be rebroadcast
851         
852         foreach my $dxchan (DXChannel->get_all) {
853                 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
854                 $dxchan->send_later('L', $s);
855         }
856 }
857
858
859 1;
860 __END__