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