add various eph timings and variables to control them
[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         # save this for them's that need it
191         my $rawline = $cmdline;
192         
193         # remove leading and trailing spaces
194         $cmdline =~ s/^\s*(.*)\s*$/$1/;
195         
196         if ($self->{state} eq 'page') {
197                 my $i = $self->{pagelth};
198                 my $ref = $self->{pagedata};
199                 my $tot = @$ref;
200                 
201                 # abort if we get a line starting in with a
202                 if ($cmdline =~ /^a/io) {
203                         undef $ref;
204                         $i = 0;
205                 }
206         
207                 # send a tranche of data
208                 while ($i-- > 0 && @$ref) {
209                         my $line = shift @$ref;
210                         $line =~ s/\s+$//o;     # why am having to do this? 
211                         $self->send($line);
212                 }
213                 
214                 # reset state if none or else chuck out an intermediate prompt
215                 if ($ref && @$ref) {
216                         $tot -= $self->{pagelth};
217                         $self->send($self->msg('page', $tot));
218                 } else {
219                         $self->state('prompt');
220                 }
221         } elsif ($self->{state} eq 'sysop') {
222                 my $passwd = $self->{user}->passwd;
223                 if ($passwd) {
224                         my @pw = grep {$_ !~ /\s/} split //, $passwd;
225                         my @l = @{$self->{passwd}};
226                         my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
227                         if ($cmdline =~ /$str/) {
228                                 $self->{priv} = $self->{user}->priv;
229                         } else {
230                                 $self->send($self->msg('sorry'));
231                         }
232                 } else {
233                         $self->send($self->msg('sorry'));
234                 }
235                 $self->state('prompt');
236         } elsif ($self->{state} eq 'passwd') {
237                 my $passwd = $self->{user}->passwd;
238                 if ($passwd && $cmdline eq $passwd) {
239                         $self->send($self->msg('pw1'));
240                         $self->state('passwd1');
241                 } else {
242                         $self->conn->{echo} = $self->conn->{decho};
243                         delete $self->conn->{decho};
244                         $self->send($self->msg('sorry'));
245                         $self->state('prompt');
246                 }
247         } elsif ($self->{state} eq 'passwd1') {
248                 $self->{passwd} = $cmdline;
249                 $self->send($self->msg('pw2'));
250                 $self->state('passwd2');
251         } elsif ($self->{state} eq 'passwd2') {
252                 if ($cmdline eq $self->{passwd}) {
253                         $self->{user}->passwd($cmdline);
254                         $self->send($self->msg('pw3'));
255                 } else {
256                         $self->send($self->msg('pw4'));
257                 }
258                 $self->conn->{echo} = $self->conn->{decho};
259                 delete $self->conn->{decho};
260                 $self->state('prompt');
261         } elsif ($self->{state} eq 'talk') {
262                 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
263                         for (@{$self->{talklist}}) {
264                                 $self->send_talks($_,  $self->msg('talkend'));
265                         }
266                         $self->state('prompt');
267                         delete $self->{talklist};
268                 } elsif ($cmdline =~ m(^/\w+)) {
269                         $cmdline =~ s(^/)();
270                         $self->send_ans(run_cmd($self, $cmdline));
271                         $self->send($self->talk_prompt);
272                 } elsif ($self->{talklist} && @{$self->{talklist}}) {
273                         # send what has been said to whoever is in this person's talk list
274                         my @bad;
275                         if (@bad = BadWords::check($cmdline)) {
276                                 $self->badcount(($self->badcount||0) + @bad);
277                                 Log('DXCommand', "$self->{call} swore: $cmdline");
278                         } else {
279                                 for (@{$self->{talklist}}) {
280                                         $self->send_talks($_, $rawline);
281                                 }
282                         }
283                         $self->send($self->talk_prompt) if $self->{state} eq 'talk';
284                 } else {
285                         # for safety
286                         $self->state('prompt');
287                 }
288         } elsif (my $func = $self->{func}) {
289                 no strict 'refs';
290                 my @ans;
291                 if (ref $self->{edit}) {
292                         eval { @ans = $self->{edit}->$func($self, $rawline)};
293                 } else {
294                         eval {  @ans = &{$self->{func}}($self, $rawline) };
295                 }
296                 if ($@) {
297                         $self->send_ans("Syserr: on stored func $self->{func}", $@);
298                         delete $self->{func};
299                         $self->state('prompt');
300                         undef $@;
301                 }
302                 $self->send_ans(@ans);
303         } else {
304                 $self->send_ans(run_cmd($self, $cmdline));
305         } 
306
307         # check for excessive swearing
308         if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
309                 Log('DXCommand', "$self->{call} logged out for excessive swearing");
310                 $self->disconnect;
311                 return;
312         }
313
314         # send a prompt only if we are in a prompt state
315         $self->prompt() if $self->{state} =~ /^prompt/o;
316 }
317
318 # send out the talk messages taking into account vias and connectivity
319 sub send_talks
320 {
321         my ($self, $ent, $line) = @_;
322         
323         my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
324         $to = $ent unless $to;
325         my $call = $via ? $via : $to;
326         my $clref = Route::get($call);
327         my $dxchan = $clref->dxchan if $clref;
328         if ($dxchan) {
329                 $dxchan->talk($self->{call}, $to, $via, $line);
330         } else {
331                 $self->send($self->msg('disc2', $via ? $via : $to));
332                 my @l = grep { $_ ne $ent } @{$self->{talklist}};
333                 if (@l) {
334                         $self->{talklist} = \@l;
335                 } else {
336                         delete $self->{talklist};
337                         $self->state('prompt');
338                 }
339         }
340 }
341
342 sub talk_prompt
343 {
344         my $self = shift;
345         my @call;
346         for (@{$self->{talklist}}) {
347                 my ($to, $via) = /(\S+)>(\S+)/;
348                 $to = $_ unless $to;
349                 push @call, $to;
350         }
351         return $self->msg('talkprompt', join(',', @call));
352 }
353
354 #
355 # send a load of stuff to a command user with page prompting
356 # and stuff
357 #
358
359 sub send_ans
360 {
361         my $self = shift;
362         
363         if ($self->{pagelth} && @_ > $self->{pagelth}) {
364                 my $i;
365                 for ($i = $self->{pagelth}; $i-- > 0; ) {
366                         my $line = shift @_;
367                         $line =~ s/\s+$//o;     # why am having to do this? 
368                         $self->send($line);
369                 }
370                 $self->{pagedata} =  [ @_ ];
371                 $self->state('page');
372                 $self->send($self->msg('page', scalar @_));
373         } else {
374                 for (@_) {
375                         if (defined $_) {
376                                 $self->send($_);
377                         } else {
378                                 $self->send('');
379                         }
380                 }
381         } 
382 }
383
384 # this is the thing that runs the command, it is done like this for the 
385 # benefit of remote command execution
386 #
387
388 sub run_cmd
389 {
390         my $self = shift;
391         my $user = $self->{user};
392         my $call = $self->{call};
393         my $cmdline = shift;
394         my @ans;
395         
396
397         return () if length $cmdline == 0;
398                 
399         # strip out //
400         $cmdline =~ s|//|/|og;
401                 
402         # split the command line up into parts, the first part is the command
403         my ($cmd, $args) = split /\s+/, $cmdline, 2;
404         $args = "" unless defined $args;
405                 
406         if ($cmd) {
407                         
408                 my ($path, $fcmd);
409                         
410                 dbg("cmd: $cmd") if isdbg('command');
411                         
412                 # alias it if possible
413                 my $acmd = CmdAlias::get_cmd($cmd);
414                 if ($acmd) {
415                         ($cmd, $args) = split /\s+/, "$acmd $args", 2;
416                         $args = "" unless defined $args;
417                         dbg("aliased cmd: $cmd $args") if isdbg('command');
418                 }
419                         
420                 # first expand out the entry to a command
421                 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
422                 ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
423
424                 if ($path && $cmd) {
425                         dbg("path: $cmd cmd: $fcmd") if isdbg('command');
426                         
427                         my $package = find_cmd_name($path, $fcmd);
428                         return ($@) if $@;
429                                 
430                         if ($package) {
431                                 no strict 'refs';
432                                 dbg("package: $package") if isdbg('command');
433                                 eval { @ans = &$package($self, $args) };
434                                 return (DXDebug::shortmess($@)) if $@;
435                         }
436                 } else {
437                         dbg("cmd: $cmd not found") if isdbg('command');
438                         if (++$self->{errors} > $maxerrors) {
439                                 $self->send($self->msg('e26'));
440                                 $self->disconnect;
441                                 return ();
442                         } else {
443                                 return ($self->msg('e1'));
444                         }
445                 }
446         }
447         
448         my $ok = shift @ans;
449         if ($ok) {
450                 delete $self->{errors};
451         } else {
452                 if (++$self->{errors} > $maxerrors) {
453                         $self->send($self->msg('e26'));
454                         $self->disconnect;
455                         return ();
456                 }
457         }
458         return (@ans);
459 }
460
461 #
462 # This is called from inside the main cluster processing loop and is used
463 # for despatching commands that are doing some long processing job
464 #
465 sub process
466 {
467         my $t = time;
468         my @dxchan = DXChannel->get_all();
469         my $dxchan;
470         
471         foreach $dxchan (@dxchan) {
472                 next if $dxchan->sort ne 'U';  
473                 
474                 # send a prompt if no activity out on this channel
475                 if ($t >= $dxchan->t + $main::user_interval) {
476                         $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
477                         $dxchan->t($t);
478                 }
479         }
480
481         while (my ($k, $v) = each %nothereslug) {
482                 if ($main::systime >= $v + 300) {
483                         delete $nothereslug{$k};
484                 }
485         }
486 }
487
488 #
489 # finish up a user context
490 #
491 sub disconnect
492 {
493         my $self = shift;
494         my $call = $self->call;
495
496         return if $self->{disconnecting}++;
497
498         delete $self->{senddbg};
499
500         my $uref = Route::User::get($call);
501         my @rout;
502         if ($uref) {
503                 @rout = $main::routeroot->del_user($uref);
504                 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
505
506                 # issue a pc17 to everybody interested
507                 DXProt::route_pc17($main::me, $main::routeroot, $uref);
508         } else {
509                 confess "trying to disconnect a non existant user $call";
510         }
511
512         # I was the last node visited
513     $self->user->node($main::mycall);
514                 
515         # send info to all logged in thingies
516         $self->tell_login('logoutu');
517
518         Log('DXCommand', "$call disconnected");
519
520         $self->SUPER::disconnect;
521 }
522
523 #
524 # short cut to output a prompt
525 #
526
527 sub prompt
528 {
529         my $self = shift;
530         if ($self->{prompt}) {
531                 $self->send($self->{prompt});
532         } else {
533                 $self->send($self->msg($self->here ? 'pr' : 'pr2', $self->call, cldate($main::systime), ztime($main::systime)));
534         }
535 }
536
537 # broadcast a message to all users [except those mentioned after buffer]
538 sub broadcast
539 {
540         my $pkg = shift;                        # ignored
541         my $s = shift;                          # the line to be rebroadcast
542         
543     foreach my $dxchan (DXChannel->get_all()) {
544                 next unless $dxchan->{sort} eq 'U'; # only interested in user channels  
545                 next if grep $dxchan == $_, @_;
546                 $dxchan->send($s);                      # send it
547         }
548 }
549
550 # gimme all the users
551 sub get_all
552 {
553         return grep {$_->{sort} eq 'U'} DXChannel->get_all();
554 }
555
556 # run a script for this user
557 sub run_script
558 {
559         my $self = shift;
560         my $silent = shift || 0;
561         
562 }
563
564 #
565 # search for the command in the cache of short->long form commands
566 #
567
568 sub search
569 {
570         my ($path, $short_cmd, $suffix) = @_;
571         my ($apath, $acmd);
572         
573         # commands are lower case
574         $short_cmd = lc $short_cmd;
575         dbg("command: $path $short_cmd\n") if isdbg('command');
576
577         # do some checking for funny characters
578         return () if $short_cmd =~ /\/$/;
579
580         # return immediately if we have it
581         ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
582         if ($apath && $acmd) {
583                 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
584                 return ($apath, $acmd);
585         }
586         
587         # if not guess
588         my @parts = split '/', $short_cmd;
589         my $dirfn;
590         my $curdir = $path;
591         my $p;
592         my $i;
593         my @lparts;
594         
595         for ($i = 0; $i < @parts; $i++) {
596                 my  $p = $parts[$i];
597                 opendir(D, $curdir) or confess "can't open $curdir $!";
598                 my @ls = readdir D;
599                 closedir D;
600                 my $l;
601                 foreach $l (sort @ls) {
602                         next if $l =~ /^\./;
603                         if ($i < $#parts) {             # we are dealing with directories
604                                 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
605                                         dbg("got dir: $curdir/$l\n") if isdbg('command');
606                                         $dirfn .= "$l/";
607                                         $curdir .= "/$l";
608                                         last;
609                                 }
610                         } else {                        # we are dealing with commands
611                                 @lparts = split /\./, $l;                  
612                                 next if $lparts[$#lparts] ne $suffix;        # only look for .$suffix files
613                                 if ($p eq substr($l, 0, length $p)) {
614                                         pop @lparts; #  remove the suffix
615                                         $l = join '.', @lparts;
616                                         #                 chop $dirfn;               # remove trailing /
617                                         $dirfn = "" unless $dirfn;
618                                         $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
619                                         dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
620                                         return ($path, "$dirfn$l"); 
621                                 }
622                         }
623                 }
624         }
625         return ();  
626 }  
627
628 # clear the command name cache
629 sub clear_cmd_cache
630 {
631         no strict 'refs';
632         
633         for (keys %Cache) {
634                 undef *{$_};
635                 dbg("Undefining cmd $_") if isdbg('command');
636         }
637         %cmd_cache = ();
638         %Cache = ();
639 }
640
641 #
642 # the persistant execution of things from the command directories
643 #
644 #
645 # This allows perl programs to call functions dynamically
646
647 # This has been nicked directly from the perlembed pages
648 #
649
650 #require Devel::Symdump;  
651
652 sub valid_package_name {
653         my($string) = @_;
654         $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
655         
656         $string =~ s|/|_|g;
657         return "cmd_$string";
658 }
659
660
661 # this bit of magic finds a command in the offered directory
662 sub find_cmd_name {
663         my $path = shift;
664         my $cmdname = shift;
665         my $package = valid_package_name($cmdname);
666         my $filename = "$path/$cmdname.pl";
667         my $mtime = -M $filename;
668         
669         # return if we can't find it
670         $errstr = undef;
671         unless (defined $mtime) {
672                 $errstr = DXM::msg('e1');
673                 return undef;
674         }
675         
676         if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
677                 #we have compiled this subroutine already,
678                 #it has not been updated on disk, nothing left to do
679                 #print STDERR "already compiled $package->handler\n";
680                 ;
681         } else {
682
683                 my $sub = readfilestr($filename);
684                 unless ($sub) {
685                         $errstr = "Syserr: can't open '$filename' $!";
686                         return undef;
687                 };
688                 
689                 #wrap the code into a subroutine inside our unique package
690                 my $eval = qq( sub $package { $sub } );
691                 
692                 if (isdbg('eval')) {
693                         my @list = split /\n/, $eval;
694                         my $line;
695                         for (@list) {
696                                 dbg($_ . "\n") if isdbg('eval');
697                         }
698                 }
699                 
700                 # get rid of any existing sub and try to compile the new one
701                 no strict 'refs';
702
703                 if (exists $Cache{$package}) {
704                         dbg("Redefining $package") if isdbg('command');
705                         undef *$package;
706                 } else {
707                         dbg("Defining $package") if isdbg('command');
708                 }
709                 eval $eval;
710                 
711                 $Cache{$package} = {mtime => $mtime };
712             
713         }
714
715         return $package;
716 }
717
718 sub local_send
719 {
720         my ($self, $let, $buf) = @_;
721         if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
722                 if ($self->{enhanced}) {
723                         $self->send_later($let, $buf);
724                 } else {
725                         $self->send($buf);
726                 }
727         } else {
728                 $self->delay($buf);
729         }
730 }
731
732 # send a talk message here
733 sub talk
734 {
735         my ($self, $from, $to, $via, $line) = @_;
736         $line =~ s/\\5E/\^/g;
737         $self->local_send('T', "$to de $from: $line") if $self->{talk};
738         Log('talk', $to, $from, $via?$via:$main::mycall, $line);
739         # send a 'not here' message if required
740         unless ($self->{here} && $from ne $to) {
741                 my $key = "$to$from";
742                 unless (exists $nothereslug{$key}) {
743                         my ($ref, $dxchan);
744                         if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
745                                 my $name = $self->user->name || $to;
746                                 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
747                                 $nothereslug{$key} = $main::systime;
748                                 $dxchan->talk($to, $from, undef, $s);
749                         }
750                 }
751         }
752 }
753
754 # send an announce
755 sub announce
756 {
757         my $self = shift;
758         my $line = shift;
759         my $isolate = shift;
760         my $to = shift;
761         my $target = shift;
762         my $text = shift;
763         my ($filter, $hops);
764
765         if (!$self->{ann_talk} && $to ne $self->{call}) {
766                 my $call = AnnTalk::is_talk_candidate($_[0], $text);
767                 return if $call;
768         }
769
770         if ($self->{annfilter}) {
771                 ($filter, $hops) = $self->{annfilter}->it(@_ );
772                 return unless $filter;
773         }
774
775         unless ($self->{ann}) {
776                 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
777         }
778         return if $target eq 'SYSOP' && $self->{priv} < 5;
779         my $buf = "$to$target de $_[0]: $text";
780         $buf =~ s/\%5E/^/g;
781         $buf .= "\a\a" if $self->{beep};
782         $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
783 }
784
785 # send a dx spot
786 sub dx_spot
787 {
788         my $self = shift;
789         my $line = shift;
790         my $isolate = shift;
791         my ($filter, $hops);
792
793         return unless $self->{dx};
794         
795         if ($self->{spotsfilter}) {
796                 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
797                 return unless $filter;
798         }
799
800
801         my $t = ztime($_[2]);
802         my $ref = DXUser->get_current($_[4]);
803         my $loc = $ref->qra if $ref && $ref->qra && $self->{user}->wantgrid;
804         $loc = ' ' . substr($loc, 0, 4) if $loc;
805         $loc = "" unless $loc;
806         my $buf = sprintf "DX de %-7.7s%11.1f  %-12.12s %-*s $t$loc", "$_[4]:", $_[0], $_[1], $self->{consort} eq 'local' ? 29 : 30, $_[3];
807         $buf .= "\a\a" if $self->{beep};
808         $buf =~ s/\%5E/^/g;
809         $self->local_send('X', $buf);
810 }
811
812 sub wwv
813 {
814         my $self = shift;
815         my $line = shift;
816         my $isolate = shift;
817         my ($filter, $hops);
818
819         return unless $self->{wwv};
820         
821         if ($self->{wwvfilter}) {
822                 ($filter, $hops) = $self->{wwvfilter}->it(@_ );
823                 return unless $filter;
824         }
825
826         my $buf = "WWV de $_[6] <$_[1]>:   SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
827         $buf .= "\a\a" if $self->{beep};
828         $self->local_send('V', $buf);
829 }
830
831 sub wcy
832 {
833         my $self = shift;
834         my $line = shift;
835         my $isolate = shift;
836         my ($filter, $hops);
837
838         return unless $self->{wcy};
839         
840         if ($self->{wcyfilter}) {
841                 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
842                 return unless $filter;
843         }
844
845         my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
846         $buf .= "\a\a" if $self->{beep};
847         $self->local_send('Y', $buf);
848 }
849
850 # broadcast debug stuff to all interested parties
851 sub broadcast_debug
852 {
853         my $s = shift;                          # the line to be rebroadcast
854         
855         foreach my $dxchan (DXChannel->get_all) {
856                 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
857                 $dxchan->send_later('L', $s);
858         }
859 }
860
861
862 1;
863 __END__