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