fix up times and move things around for pc92
[spider.git] / perl / DXProt.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the protocal mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXProt;
11
12 @ISA = qw(DXChannel);
13
14 use DXUtil;
15 use DXChannel;
16 use DXUser;
17 use DXM;
18 use DXProtVars;
19 use DXCommandmode;
20 use DXLog;
21 use Spot;
22 use DXProtout;
23 use DXDebug;
24 use Filter;
25 use Local;
26 use DXDb;
27 use AnnTalk;
28 use Geomag;
29 use WCY;
30 use BadWords;
31 use DXHash;
32 use Route;
33 use Route::Node;
34 use Script;
35 use RouteDB;
36 use DXProtHandle;
37
38 use strict;
39
40 use vars qw($VERSION $BRANCH);
41 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
42 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
43 $main::build += $VERSION;
44 $main::branch += $BRANCH;
45
46 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
47                         $last_hour $last10 %eph  %pings %rcmds $ann_to_talk
48                         $pingint $obscount %pc19list $chatdupeage $chatimportfn
49                         $investigation_int $pc19_version $myprot_version
50                         %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
51                         $allowzero $decode_dk0wcy $send_opernam @checklist
52                         $eph_pc15_restime $pc92_update_period $last_pc92_update
53                    );
54
55 $pc11_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc11
56 $pc23_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc23
57
58 $last_hour = time;                              # last time I did an hourly periodic update
59 %rcmds = ();                    # outstanding rcmd requests outbound
60 %nodehops = ();                 # node specific hop control
61 %pc19list = ();                                 # list of outstanding PC19s that haven't had PC16s on them
62
63 $censorpc = 1;                                  # Do a BadWords::check on text fields and reject things
64                                                                 # loads of 'bad things'
65 $baddx = new DXHash "baddx";
66 $badspotter = new DXHash "badspotter";
67 $badnode = new DXHash "badnode";
68 $last10 = $last_pc50 = time;
69 $ann_to_talk = 1;
70 $rspfcheck = 1;
71 $eph_restime = 180;
72 $eph_info_restime = 60*60;
73 $eph_pc15_restime = 6*60;
74 $eph_pc34_restime = 30;
75 $pingint = 5*60;
76 $obscount = 2;
77 $chatdupeage = 20 * 60 * 60;
78 $chatimportfn = "$main::root/chat_import";
79 $investigation_int = 12*60*60;  # time between checks to see if we can see this node
80 $pc19_version = 5466;                   # the visible version no for outgoing PC19s generated from pc59
81 $pc92_update_period = 60*60;    # the period between PC92 C updates
82 $last_pc92_update = time;               # the last time a PC92 config update
83
84
85 @checklist = 
86 (
87  [ qw(i c c m bp bc c) ],                       # pc10
88  [ qw(i f m d t m c c h) ],             # pc11
89  [ qw(i c bm m bm bm p h) ],            # pc12
90  [ qw(i c h) ],                                 # 
91  [ qw(i c h) ],                                 # 
92  [ qw(i c m h) ],                                       # 
93  undef ,                                                # pc16 has to be validated manually
94  [ qw(i c c h) ],                                       # pc17
95  [ qw(i m n) ],                                 # pc18
96  undef ,                                                # pc19 has to be validated manually
97  undef ,                                                # pc20 no validation
98  [ qw(i c m h) ],                                       # pc21
99  undef ,                                                # pc22 no validation
100  [ qw(i d n n n n m c c h) ],           # pc23
101  [ qw(i c p h) ],                                       # pc24
102  [ qw(i c c n n) ],                             # pc25
103  [ qw(i f m d t m c c bc) ],            # pc26
104  [ qw(i d n n n n m c c bc) ],  # pc27
105  [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
106  [ qw(i c c n m) ],                             # pc29
107  [ qw(i c c n) ],                                       # pc30
108  [ qw(i c c n) ],                                       # pc31
109  [ qw(i c c n) ],                                       # pc32
110  [ qw(i c c n) ],                                       # pc33
111  [ qw(i c c m) ],                                       # pc34
112  [ qw(i c c m) ],                                       # pc35
113  [ qw(i c c m) ],                                       # pc36
114  [ qw(i c c n m) ],                             # pc37
115  undef,                                                 # pc38 not interested
116  [ qw(i c m) ],                                 # pc39
117  [ qw(i c c m p n) ],                           # pc40
118  [ qw(i c n m h) ],                             # pc41
119  [ qw(i c c n) ],                                       # pc42
120  undef,                                                 # pc43 don't handle it
121  [ qw(i c c n m m c) ],                 # pc44
122  [ qw(i c c n m) ],                             # pc45
123  [ qw(i c c n) ],                                       # pc46
124  undef,                                                 # pc47
125  undef,                                                 # pc48
126  [ qw(i c m h) ],                                       # pc49
127  [ qw(i c n h) ],                                       # pc50
128  [ qw(i c c n) ],                                       # pc51
129  undef,
130  undef,
131  undef,
132  undef,
133  undef,
134  undef,
135  undef,
136  undef,
137  undef,                                                 # pc60
138  undef,
139  undef,
140  undef,
141  undef,
142  undef,
143  undef,
144  undef,
145  undef,
146  undef,
147  undef,                                                 # pc70
148  undef,
149  undef,
150  [ qw(i d n n n n n n m m m c c h) ],   # pc73
151  undef,
152  undef,
153  undef,
154  undef,
155  undef,
156  undef,
157  undef,                                                 # pc80
158  undef,
159  undef,
160  undef,
161  [ qw(i c c c m) ],                             # pc84
162  [ qw(i c c c m) ],                             # pc85
163  undef,
164  undef,
165  undef,
166  undef,
167  [ qw(i c n) ],                                 # pc90
168 );
169
170 # use the entry in the check list to check the field list presented
171 # return OK if line NOT in check list (for now)
172 sub check
173 {
174         my $n = shift;
175         $n -= 10;
176         return 0 if $n < 0 || $n > @checklist; 
177         my $ref = $checklist[$n];
178         return 0 unless ref $ref;
179         
180         my $i;
181         for ($i = 1; $i < @$ref; $i++) {
182                 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
183                 return 0 unless $act;
184                 next if $blank && $_[$i] =~ /^[ \*]$/;
185                 if ($act eq 'c') {
186                         return $i unless is_callsign($_[$i]);
187                 } elsif ($act eq 'i') {                 
188                         ;                                       # do nothing
189                 } elsif ($act eq 'm') {
190                         return $i unless is_pctext($_[$i]);
191                 } elsif ($act eq 'p') {
192                         return $i unless is_pcflag($_[$i]);
193                 } elsif ($act eq 'f') {
194                         return $i unless is_freq($_[$i]);
195                 } elsif ($act eq 'n') {
196                         return $i unless $_[$i] =~ /^[\d ]+$/;
197                 } elsif ($act eq 'h') {
198                         return $i unless $_[$i] =~ /^H\d\d?$/;
199                 } elsif ($act eq 'd') {
200                         return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
201                 } elsif ($act eq 't') {
202                         return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
203                 } 
204         }
205         return 0;
206 }
207
208 sub init
209 {
210         do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
211         confess $@ if $@;
212
213         my $user = DXUser->get($main::mycall);
214         die "User $main::mycall not setup or disappeared RTFM" unless $user;
215         
216         $myprot_version += $main::version*100;
217         $main::me = DXProt->new($main::mycall, 0, $user); 
218         $main::me->{here} = 1;
219         $main::me->{state} = "indifferent";
220         $main::me->{sort} = 'S';    # S for spider
221         $main::me->{priv} = 9;
222         $main::me->{metric} = 0;
223         $main::me->{pingave} = 0;
224         $main::me->{registered} = 1;
225         $main::me->{version} = $main::version;
226         $main::me->{build} = $main::build;
227 }
228
229 #
230 # obtain a new connection this is derived from dxchannel
231 #
232
233 sub new 
234 {
235         my $self = DXChannel::alloc(@_);
236
237         # add this node to the table, the values get filled in later
238         my $pkg = shift;
239         my $call = shift;
240         $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
241
242         return $self;
243 }
244
245 # this is how a pc connection starts (for an incoming connection)
246 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
247 # all the crap that comes between).
248 sub start
249 {
250         my ($self, $line, $sort) = @_;
251         my $call = $self->{call};
252         my $user = $self->{user};
253
254         # log it
255         my $host = $self->{conn}->{peerhost};
256         $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
257         $host ||= "unknown";
258
259         Log('DXProt', "$call connected from $host");
260         
261         # remember type of connection
262         $self->{consort} = $line;
263         $self->{outbound} = $sort eq 'O';
264         my $priv = $user->priv;
265         $priv = $user->priv(1) unless $priv;
266         $self->{priv} = $priv;     # other clusters can always be 'normal' users
267         $self->{lang} = $user->lang || 'en';
268         $self->{isolate} = $user->{isolate};
269         $self->{consort} = $line;       # save the connection type
270         $self->{here} = 1;
271         $self->{width} = 80;
272
273         # sort out registration
274         $self->{registered} = 1;
275
276         # get the output filters
277         $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
278         $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
279         $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
280         $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
281         $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
282
283
284         # get the INPUT filters (these only pertain to Clusters)
285         $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
286         $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
287         $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
288         $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
289         $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
290         
291         # set unbuffered and no echo
292         $self->send_now('B',"0");
293         $self->send_now('E',"0");
294         $self->conn->echo(0) if $self->conn->can('echo');
295         
296         # ping neighbour node stuff
297         my $ping = $user->pingint;
298         $ping = $pingint unless defined $ping;
299         $self->{pingint} = $ping;
300         $self->{nopings} = $user->nopings || $obscount;
301         $self->{pingtime} = [ ];
302         $self->{pingave} = 999;
303         $self->{metric} ||= 100;
304         $self->{lastping} = $main::systime;
305         
306         # send initialisation string
307         unless ($self->{outbound}) {
308                 $self->sendinit;
309         }
310         
311         $self->state('init');
312         $self->{pc50_t} = $main::systime;
313
314         # send info to all logged in thingies
315         $self->tell_login('loginn');
316
317         # run a script send the output to the debug file
318         my $script = new Script(lc $call) || new Script('node_default');
319         $script->run($self) if $script;
320 }
321
322 #
323 # send outgoing 'challenge'
324 #
325
326 sub sendinit
327 {
328         my $self = shift;
329         $self->send(pc18());
330 }
331
332 #
333 # This is the normal pcxx despatcher
334 #
335 sub normal
336 {
337         my ($self, $line) = @_;
338
339         if ($line =~ '^<\w+\s' && $main::do_xml) {
340                 DXXml::normal($self, $line);
341                 return;
342         }
343
344         my @field = split /\^/, $line;
345         return unless @field;
346         
347         pop @field if $field[-1] eq '~';
348         
349 #       print join(',', @field), "\n";
350                                                 
351         
352         # process PC frames, this will fail unless the frame starts PCnn
353         my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
354         unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
355                 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
356                 return;
357         }
358
359         # check for and dump bad protocol messages
360         my $n = check($pcno, @field);
361         if ($n) {
362                 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
363                 return;
364         }
365
366         # modify the hop count here
367         if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
368                 $trail ||= '';
369                 $hops--;
370                 return if $hops < 0;
371                 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
372                 $field[-1] = "H$hops";
373         }
374
375         # send it out for processing
376         my $origin = $self->{call};
377         no strict 'subs';
378         my $sub = "handle_$pcno";
379
380         if ($self->can($sub)) {
381                 $self->$sub($pcno, $line, $origin, @field);
382         } else {
383                 $self->handle_default($pcno, $line, $origin, @field);
384         }
385 }
386
387 #
388 # This is called from inside the main cluster processing loop and is used
389 # for despatching commands that are doing some long processing job
390 #
391 sub process
392 {
393         my $t = time;
394         my @dxchan = DXChannel::get_all();
395         my $dxchan;
396         my $pc50s;
397         
398         # send out a pc50 on EVERY channel all at once
399         if ($t >= $last_pc50 + $DXProt::pc50_interval) {
400                 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
401                 eph_dup($pc50s);
402                 $last_pc50 = $t;
403         }
404
405         foreach $dxchan (@dxchan) {
406                 next unless $dxchan->is_node;
407                 next if $dxchan->handle_xml;
408                 next if $dxchan == $main::me;
409
410                 # send the pc50
411                 $dxchan->send($pc50s) if $pc50s;
412                 
413                 # send a ping out on this channel
414                 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
415                         if ($dxchan->{nopings} <= 0) {
416                                 $dxchan->disconnect;
417                         } else {
418                                 DXXml::Ping::add($main::me, $dxchan->call);
419                                 $dxchan->{nopings} -= 1;
420                                 $dxchan->{lastping} = $t;
421                                 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
422                         }
423                 }
424         }
425
426         Investigate::process();
427
428         # every ten seconds
429         if ($t - $last10 >= 10) {       
430                 # clean out ephemera 
431
432                 eph_clean();
433                 import_chat();
434
435                 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
436                         send_pc92_update();
437                         $last_pc92_update = $main::systime;
438                 }
439                 
440                 $last10 = $t;
441         }
442         
443         if ($main::systime - 3600 > $last_hour) {
444                 $last_hour = $main::systime;
445         }
446 }
447
448 #
449 # finish up a pc context
450 #
451
452 #
453 # some active measures
454 #
455
456
457 sub send_dx_spot
458 {
459         my $self = shift;
460         my $line = shift;
461         my @dxchan = DXChannel::get_all();
462         my $dxchan;
463         
464         # send it if it isn't the except list and isn't isolated and still has a hop count
465         # taking into account filtering and so on
466         foreach $dxchan (@dxchan) {
467                 next if $dxchan == $main::me;
468                 next if $dxchan == $self && $self->is_node;
469                 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
470         }
471 }
472
473 sub dx_spot
474 {
475         my $self = shift;
476         my $line = shift;
477         my $isolate = shift;
478         my ($filter, $hops);
479
480         if ($self->{spotsfilter}) {
481                 ($filter, $hops) = $self->{spotsfilter}->it(@_);
482                 return unless $filter;
483         }
484         send_prot_line($self, $filter, $hops, $isolate, $line);
485 }
486
487 sub send_prot_line
488 {
489         my ($self, $filter, $hops, $isolate, $line) = @_;
490         my $routeit;
491
492
493         if ($hops) {
494                 $routeit = $line;
495                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
496         } else {
497                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
498                 return unless $routeit;
499         }
500         if ($filter) {
501                 $self->send($routeit);
502         } else {
503                 $self->send($routeit) unless $self->{isolate} || $isolate;
504         }
505 }
506
507
508 sub send_wwv_spot
509 {
510         my $self = shift;
511         my $line = shift;
512         my @dxchan = DXChannel::get_all();
513         my $dxchan;
514         my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
515
516         # send it if it isn't the except list and isn't isolated and still has a hop count
517         # taking into account filtering and so on
518         foreach $dxchan (@dxchan) {
519                 next if $dxchan == $main::me;
520                 next if $dxchan == $self && $self->is_node;
521                 my $routeit;
522                 my ($filter, $hops);
523
524                 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
525         }
526 }
527
528 sub wwv
529 {
530         my $self = shift;
531         my $line = shift;
532         my $isolate = shift;
533         my ($filter, $hops);
534         
535         if ($self->{wwvfilter}) {
536                 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
537                 return unless $filter;
538         }
539         send_prot_line($self, $filter, $hops, $isolate, $line)
540 }
541
542 sub send_wcy_spot
543 {
544         my $self = shift;
545         my $line = shift;
546         my @dxchan = DXChannel::get_all();
547         my $dxchan;
548         my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
549         
550         # send it if it isn't the except list and isn't isolated and still has a hop count
551         # taking into account filtering and so on
552         foreach $dxchan (@dxchan) {
553                 next if $dxchan == $main::me;
554                 next if $dxchan == $self;
555
556                 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
557         }
558 }
559
560 sub wcy
561 {
562         my $self = shift;
563         my $line = shift;
564         my $isolate = shift;
565         my ($filter, $hops);
566
567         if ($self->{wcyfilter}) {
568                 ($filter, $hops) = $self->{wcyfilter}->it(@_);
569                 return unless $filter;
570         }
571         send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
572 }
573
574 # send an announce
575 sub send_announce
576 {
577         my $self = shift;
578         my $line = shift;
579         my @dxchan = DXChannel::get_all();
580         my $dxchan;
581         my $target;
582         my $to = 'To ';
583         my $text = unpad($_[2]);
584                                 
585         if ($_[3] eq '*') {     # sysops
586                 $target = "SYSOP";
587         } elsif ($_[3] gt ' ') { # speciality list handling
588                 my ($name) = split /\./, $_[3]; 
589                 $target = "$name"; # put the rest in later (if bothered) 
590         } 
591         
592         if ($_[5] eq '1') {
593                 $target = "WX"; 
594                 $to = '';
595         }
596         $target = "ALL" if !$target;
597
598
599         # obtain country codes etc 
600         my @a = Prefix::cty_data($_[0]);
601         my @b = Prefix::cty_data($_[4]);
602         if ($self->{inannfilter}) {
603                 my ($filter, $hops) = 
604                         $self->{inannfilter}->it(@_, $self->{call}, 
605                                                                          @a[0..2],
606                                                                          @b[0..2], $a[3], $b[3]);
607                 unless ($filter) {
608                         dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
609                         return;
610                 }
611         }
612
613         if (AnnTalk::dup($_[0], $_[1], $_[2])) {
614                 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
615                 return;
616         }
617
618         Log('ann', $target, $_[0], $text);
619
620         # send it if it isn't the except list and isn't isolated and still has a hop count
621         # taking into account filtering and so on
622         foreach $dxchan (@dxchan) {
623                 next if $dxchan == $main::me;
624                 next if $dxchan == $self && $self->is_node;
625                 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
626                                                   @a[0..2], @b[0..2]);
627         }
628 }
629
630 my $msgid = 0;
631
632 sub nextchatmsgid
633 {
634         $msgid++;
635         $msgid = 1 if $msgid > 999;
636         return $msgid;
637 }
638
639 # send a chat line
640 sub send_chat
641 {
642         my $self = shift;
643         my $line = shift;
644         my @dxchan = DXChannel::get_all();
645         my $dxchan;
646         my $target = $_[3];
647         my $text = unpad($_[2]);
648         my $ak1a_line;
649                                 
650         # munge the group and recast the line if required
651         if ($target =~ s/\.LST$//) {
652                 $ak1a_line = $line;
653         }
654         
655         # obtain country codes etc 
656         my @a = Prefix::cty_data($_[0]);
657         my @b = Prefix::cty_data($_[4]);
658         if ($self->{inannfilter}) {
659                 my ($filter, $hops) = 
660                         $self->{inannfilter}->it(@_, $self->{call}, 
661                                                                          @a[0..2],
662                                                                          @b[0..2], $a[3], $b[3]);
663                 unless ($filter) {
664                         dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
665                         return;
666                 }
667         }
668
669         if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
670                 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
671                 return;
672         }
673
674
675         Log('chat', $target, $_[0], $text);
676
677         # send it if it isn't the except list and isn't isolated and still has a hop count
678         # taking into account filtering and so on
679         foreach $dxchan (@dxchan) {
680                 my $is_ak1a = $dxchan->is_ak1a;
681                 
682                 if ($dxchan->is_node) {
683                         next if $dxchan == $main::me;
684                         next if $dxchan == $self;
685                         next unless $dxchan->is_spider || $is_ak1a;
686                         next if $target eq 'LOCAL';
687                         if (!$ak1a_line && $is_ak1a) {
688                                 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
689                         }
690                 }
691                 
692                 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1], 
693                                           $text, @_, $self->{call}, @a[0..2], @b[0..2]);
694         }
695 }
696
697 sub announce
698 {
699         my $self = shift;
700         my $line = shift;
701         my $isolate = shift;
702         my $to = shift;
703         my $target = shift;
704         my $text = shift;
705         my ($filter, $hops);
706
707         if ($self->{annfilter}) {
708                 ($filter, $hops) = $self->{annfilter}->it(@_);
709                 return unless $filter;
710         }
711         send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
712 }
713
714 sub chat
715 {
716         goto &announce;
717 }
718
719
720 sub send_local_config
721 {
722         my $self = shift;
723
724         dbg('DXProt::send_local_config') if isdbg('trace');
725
726         # send our nodes
727         if ($self->{do_pc92}) { 
728                 $self->send_pc92_config;
729         } else {
730                 my $node;
731                 my @nodes;
732                 my @localnodes;
733                 my @remotenodes;
734
735                 if ($self->{isolate}) {
736                         @localnodes = ( $main::routeroot );
737                         $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
738                 } else {
739                         # create a list of all the nodes that are not connected to this connection
740                         # and are not themselves isolated, this to make sure that isolated nodes
741                         # don't appear outside of this node
742
743                         # send locally connected nodes
744                         my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
745                         @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
746                         $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
747
748                         my $node;
749                         my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
750                         my @intcalls;
751                         for $node (@rawintcalls) {
752                                 push @intcalls, $node unless grep $node eq $_, @intcalls; 
753                         }
754                         my $ref = Route::Node::get($self->{call});
755                         my @rnodes = $ref->nodes;
756                         for $node (@intcalls) {
757                                 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
758                         }
759                         $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
760                 }
761         
762                 # get all the users connected on the above nodes and send them out
763                 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
764                         if ($node) {
765                                 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
766                                 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
767                         } else {
768                                 dbg("sent a null value") if isdbg('chanerr');
769                         }
770                 }
771         }
772 }
773
774 sub gen_pc92_update
775 {
776         my $self = shift;
777         my $with_pc92_nodes = shift;
778         my $node;
779         my @lines;
780         
781         dbg('DXProt::send_pc92_update') if isdbg('trace');
782
783         # send 'my' configuration for all users and pc92 capable nodes
784         my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
785         my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
786 #       push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
787         push @lines, pc92c($main::routeroot, @localnodes);
788
789
790         if ($with_pc92_nodes) {
791                 # send out the configuration of all the PC92 nodes with current configuration
792                 # but with the dates that the last config came in with.
793                 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc92} } DXChannel::get_all_nodes();
794                 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
795                 foreach $node (@localnodes) {
796                         if ($node && $node->lastid->{92}) {
797                                 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
798                                 push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
799                         }
800                 }
801         }
802         
803         # send the configuration of all the 'external' nodes that don't handle PC92
804         # out with the 'external' marker on the first node.
805         @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
806         @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
807         foreach $node (@localnodes) {
808                 if ($node) {
809                         my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
810                         push @lines, pc92c($node, @rout);
811                 } 
812         }
813         return @lines;
814 }
815
816
817 sub send_pc92_config
818 {
819         my $self = shift;
820
821         dbg('DXProt::send_pc92_config') if isdbg('trace');
822
823         my @out = $self->gen_pc92_update(1);
824         
825         # send the complete config out on this interface
826         for (@out) {
827                 $self->send($_);
828         }
829
830
831 sub send_pc92_update
832 {
833         my @out = $main::me->gen_pc92_update(0);
834         
835         # broadcast the lines to all PC92 nodes
836         for (@out) {
837                 $main::me->broadcast_route_pc9x('', undef, $_, 0);
838         }
839
840
841 #
842 # route a message down an appropriate interface for a callsign
843 #
844 # is called route(to, pcline);
845 #
846
847 sub route
848 {
849         my ($self, $call, $line) = @_;
850
851         if (ref $self && $call eq $self->{call}) {
852                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
853                 return;
854         }
855
856         # always send it down the local interface if available
857         my $dxchan = DXChannel::get($call);
858         if ($dxchan) {
859                 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
860         } else {
861                 my $cl = Route::get($call);
862                 $dxchan = $cl->dxchan if $cl;
863                 if (ref $dxchan) {
864                         if (ref $self && $dxchan eq $self) {
865                                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
866                                 return;
867                         }
868                         dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
869                 }
870         }
871
872         # try the backstop method
873         unless ($dxchan) {
874                 my $rcall = RouteDB::get($call);
875                 if ($rcall) {
876                         if ($self && $rcall eq $self->{call}) {
877                                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
878                                 return;
879                         }
880                         $dxchan = DXChannel::get($rcall);
881                         dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
882                 }
883         }
884
885         if ($dxchan) {
886                 my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
887                 if ($routeit) {
888                         $dxchan->send($routeit) unless $dxchan == $main::me;
889                 }
890         } else {
891                 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
892         }
893 }
894
895 #
896 # obtain the hops from the list for this callsign and pc no 
897 #
898
899 sub get_hops
900 {
901         my $pcno = shift;
902         my $hops = $DXProt::hopcount{$pcno};
903         $hops = $DXProt::def_hopcount if !$hops;
904         return "H$hops";       
905 }
906
907
908 # adjust the hop count on a per node basis using the user loadable 
909 # hop table if available or else decrement an existing one
910 #
911
912 sub adjust_hops
913 {
914         my $self = shift;
915         my $s = shift;
916         my $call = $self->{call};
917         my $hops;
918         
919         if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
920                 my ($pcno) = $s =~ /^PC(\d\d)/o;
921                 confess "$call called adjust_hops with '$s'" unless $pcno;
922                 my $ref = $nodehops{$call} if %nodehops;
923                 if ($ref) {
924                         my $newhops = $ref->{$pcno};
925                         return "" if defined $newhops && $newhops == 0;
926                         $newhops = $ref->{default} unless $newhops;
927                         return "" if defined $newhops && $newhops == 0;
928                         $newhops = $hops if !$newhops;
929                         $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
930                 }
931         }
932         return $s;
933 }
934
935
936 # load hop tables
937 #
938 sub load_hops
939 {
940         my $self = shift;
941         return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
942         do "$main::data/hop_table.pl";
943         return $@ if $@;
944         return ();
945 }
946
947 sub process_rcmd
948 {
949         my ($self, $tonode, $fromnode, $user, $cmd) = @_;
950         if ($tonode eq $main::mycall) {
951                 my $ref = DXUser->get_current($fromnode);
952                 my $cref = Route::Node::get($fromnode);
953                 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
954                 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
955                         if ($ref->{priv}) {             # you have to have SOME privilege, the commands have further filtering
956                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
957                                 my $oldpriv = $self->{priv};
958                                 $self->{priv} = $ref->{priv}; # assume the user's privilege level
959                                 my @in = (DXCommandmode::run_cmd($self, $cmd));
960                                 $self->{priv} = $oldpriv;
961                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
962                                 delete $self->{remotecmd};
963                         } else {
964                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
965                         }
966                 } else {
967                         $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
968                 }
969         } else {
970                 my $ref = DXUser->get_current($tonode);
971                 if ($ref && $ref->is_clx) {
972                         $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
973                 } else {
974                         $self->route($tonode, pc34($fromnode, $tonode, $cmd));
975                 }
976         }
977 }
978
979 sub process_rcmd_reply
980 {
981         my ($self, $tonode, $fromnode, $user, $line) = @_;
982         if ($tonode eq $main::mycall) {
983                 my $s = $rcmds{$fromnode};
984                 if ($s) {
985                         my $dxchan = DXChannel::get($s->{call});
986                         my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
987                         $ref->send($line) if $ref;
988                         delete $rcmds{$fromnode} if !$dxchan;
989                 } else {
990                         # send unsolicited ones to the sysop
991                         my $dxchan = DXChannel::get($main::myalias);
992                         $dxchan->send($line) if $dxchan;
993                 }
994         } else {
995                 my $ref = DXUser->get_current($tonode);
996                 if ($ref && $ref->is_clx) {
997                         $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
998                 } else {
999                         $self->route($tonode, pc35($fromnode, $tonode, $line));
1000                 }
1001         }
1002 }
1003
1004 sub send_rcmd_reply
1005 {
1006         my $self = shift;
1007         my $tonode = shift;
1008         my $fromnode = shift;
1009         my $user = shift;
1010         while (@_) {
1011                 my $line = shift;
1012                 $line =~ s/\s*$//;
1013                 Log('rcmd', 'out', $fromnode, $line);
1014                 if ($self->is_clx) {
1015                         $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1016                 } else {
1017                         $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1018                 }
1019         }
1020 }
1021
1022 # add a rcmd request to the rcmd queues
1023 sub addrcmd
1024 {
1025         my ($self, $to, $cmd) = @_;
1026
1027         my $r = {};
1028         $r->{call} = $self->{call};
1029         $r->{t} = $main::systime;
1030         $r->{cmd} = $cmd;
1031         $rcmds{$to} = $r;
1032         
1033         my $ref = Route::Node::get($to);
1034         my $dxchan = $ref->dxchan;
1035         if ($dxchan && $dxchan->is_clx) {
1036                 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1037         } else {
1038                 route(undef, $to, pc34($main::mycall, $to, $cmd));
1039         }
1040 }
1041
1042 sub disconnect
1043 {
1044         my $self = shift;
1045         my $pc39flag = shift;
1046         my $call = $self->call;
1047
1048         return if $self->{disconnecting}++;
1049         
1050         unless ($pc39flag && $pc39flag == 1) {
1051                 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1052         }
1053
1054         # get rid of any PC16/17/19
1055         eph_del_regex("^PC1[679]*$call");
1056
1057         # do routing stuff, remove me from routing table
1058         my $node = Route::Node::get($call);
1059         my @rout;
1060         if ($node) {
1061                 @rout = $node->del($main::routeroot);
1062                 
1063                 # and all my ephemera as well
1064                 for (@rout) {
1065                         my $c = $_->call;
1066                         eph_del_regex("^PC1[679].*$c");
1067                 }
1068         }
1069
1070         RouteDB::delete_interface($call);
1071         
1072         # unbusy and stop and outgoing mail
1073         my $mref = DXMsg::get_busy($call);
1074         $mref->stop_msg($call) if $mref;
1075         
1076         # broadcast to all other nodes that all the nodes connected to via me are gone
1077         unless ($pc39flag && $pc39flag == 2)  {
1078                 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1079                 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1080         }
1081
1082         # remove outstanding pings
1083         delete $pings{$call};
1084         
1085         # I was the last node visited
1086     $self->user->node($main::mycall);
1087
1088         # send info to all logged in thingies
1089         $self->tell_login('logoutn');
1090
1091         Log('DXProt', $call . " Disconnected");
1092
1093         $self->SUPER::disconnect;
1094 }
1095
1096
1097
1098 # send a talk message to this thingy
1099 #
1100 sub talk
1101 {
1102         my ($self, $from, $to, $via, $line, $origin) = @_;
1103         
1104         $line =~ s/\^/\\5E/g;                   # remove any ^ characters
1105         $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1106         Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1107 }
1108
1109 # send it if it isn't the except list and isn't isolated and still has a hop count
1110 # taking into account filtering and so on
1111
1112 sub send_route
1113 {
1114         my $self = shift;
1115         my $origin = shift;
1116         my $generate = shift;
1117         my $no = shift;     # the no of things to filter on 
1118         my $routeit;
1119         my ($filter, $hops);
1120         my @rin;
1121         
1122         for (; @_ && $no; $no--) {
1123                 my $r = shift;
1124                 
1125                 if (!$self->{isolate} && $self->{routefilter}) {
1126                         $filter = undef;
1127                         if ($r) {
1128                                 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->{state}, $r->{state});
1129                                 if ($filter) {
1130                                         push @rin, $r;
1131                                 } else {
1132                                         dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1133                                 }
1134                         } else {
1135                                 dbg("was sent a null value") if isdbg('chanerr');
1136                         }
1137                 } else {
1138                         push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1139                 }
1140         }
1141         if (@rin) {
1142                 foreach my $line (&$generate(@rin, @_)) {
1143                         if ($hops) {
1144                                 $routeit = $line;
1145                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1146                         } else {
1147                                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
1148                                 next unless $routeit;
1149                         }
1150                         
1151                         $self->send($routeit);
1152                 }
1153         }
1154 }
1155
1156 sub broadcast_route
1157 {
1158         my $self = shift;
1159         my $origin = shift;
1160         my $generate = shift;
1161         my $line = shift;
1162         my @dxchan = DXChannel::get_all_nodes();
1163         my $dxchan;
1164
1165         if ($line) {
1166                 $line =~ /\^H(\d+)\^?\~?$/;
1167                 return unless $1 > 0;
1168         }
1169         unless ($self->{isolate}) {
1170                 foreach $dxchan (@dxchan) {
1171                         next if $dxchan == $self;
1172                         next if $dxchan == $main::me;
1173                         next unless $dxchan->isa('DXProt');
1174                         next if $dxchan->{do_pc92};
1175                         next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1176  
1177                         $dxchan->send_route($origin, $generate, @_);
1178                 }
1179         }
1180 }
1181
1182 # this is only used for next door nodes on init
1183 sub send_route_pc92
1184 {
1185         my $self = shift;
1186
1187         return unless $self->{do_pc92};
1188         
1189         my $origin = shift;
1190         my $generate = shift;
1191         my $no = shift;     # the no of things to filter on 
1192         my $line;
1193
1194         $line = &$generate(@_);
1195         $self->send($line);
1196 }
1197
1198 sub broadcast_route_pc9x
1199 {
1200         my $self = shift;
1201         my $origin = shift;
1202         my $generate = shift;
1203         my $line = shift;
1204         my $no = shift;
1205         my @dxchan = DXChannel::get_all_nodes();
1206         my $dxchan;
1207
1208         if ($origin eq $main::mycall) {
1209                 $line = &$generate(@_);
1210         } 
1211
1212         $line =~ /\^H(\d+)\^\~?$/;
1213         unless ($1 > 0 && $self->{isolate}) {
1214                 foreach $dxchan (@dxchan) {
1215                         next if $dxchan == $self;
1216                         next if $dxchan == $main::me;
1217                         next unless $dxchan->{do_pc92};
1218                         next unless $dxchan->isa('DXProt');
1219
1220                         $dxchan->send($line);
1221                 }
1222         }
1223 }
1224
1225 sub route_pc16
1226 {
1227         my $self = shift;
1228         return unless $self->user->wantpc16;
1229         my $origin = shift;
1230         my $line = shift;
1231         broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1232 }
1233
1234 sub route_pc17
1235 {
1236         my $self = shift;
1237         return unless $self->user->wantpc16;
1238         my $origin = shift;
1239         my $line = shift;
1240         broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1241 }
1242
1243 sub route_pc19
1244 {
1245         my $self = shift;
1246         my $origin = shift;
1247         my $line = shift;
1248         broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1249 }
1250
1251 sub route_pc21
1252 {
1253         my $self = shift;
1254         my $origin = shift;
1255         my $line = shift;
1256         broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1257 }
1258
1259 sub route_pc24
1260 {
1261         my $self = shift;
1262         my $origin = shift;
1263         my $line = shift;
1264         broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1265 }
1266
1267 sub route_pc41
1268 {
1269         my $self = shift;
1270         my $origin = shift;
1271         my $line = shift;
1272         broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1273 }
1274
1275 sub route_pc50
1276 {
1277         my $self = shift;
1278         my $origin = shift;
1279         my $line = shift;
1280         broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1281 }
1282
1283 sub route_pc92c
1284 {
1285         my $self = shift;
1286         my $origin = shift;
1287         my $line = shift;
1288         broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1289 }
1290
1291 sub route_pc92a
1292 {
1293         my $self = shift;
1294         my $origin = shift;
1295         my $line = shift;
1296         broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1297 }
1298
1299 sub route_pc92d
1300 {
1301         my $self = shift;
1302         my $origin = shift;
1303         my $line = shift;
1304         broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1305 }
1306
1307 sub in_filter_route
1308 {
1309         my $self = shift;
1310         my $r = shift;
1311         my ($filter, $hops) = (1, 1);
1312         
1313         if ($self->{inroutefilter}) {
1314                 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->state, $r->state);
1315                 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1316         }
1317         return $filter;
1318 }
1319
1320 sub eph_dup
1321 {
1322         my $s = shift;
1323         my $t = shift || $eph_restime;
1324         my $r;
1325
1326         # chop the end off
1327         $s =~ s/\^H\d\d?\^?\~?$//;
1328         $r = 1 if exists $eph{$s};    # pump up the dup if it keeps circulating
1329         $eph{$s} = $main::systime + $t;
1330         dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr'); 
1331         return $r;
1332 }
1333
1334 sub eph_del_regex
1335 {
1336         my $regex = shift;
1337         my ($key, $val);
1338         while (($key, $val) = each %eph) {
1339                 if ($key =~ m{$regex}) {
1340                         delete $eph{$key};
1341                 }
1342         }
1343 }
1344
1345 sub eph_clean
1346 {
1347         my ($key, $val);
1348         
1349         while (($key, $val) = each %eph) {
1350                 if ($main::systime >= $val) {
1351                         delete $eph{$key};
1352                 }
1353         }
1354 }
1355
1356 sub eph_list
1357 {
1358         my ($key, $val);
1359         my @out;
1360
1361         while (($key, $val) = each %eph) {
1362                 push @out, $key, $val;
1363         }
1364         return @out;
1365 }
1366
1367 sub run_cmd
1368 {
1369         goto &DXCommandmode::run_cmd;
1370 }
1371
1372
1373 # import any msgs in the chat directory
1374 # the messages are sent to the chat group which forms the
1375 # the first part of the name (eg: solar.1243.txt would be
1376 # sent to chat group SOLAR)
1377
1378 # Each message found is sent: one non-blank line to one chat
1379 # message. So 4 lines = 4 chat messages.
1380
1381 # The special name LOCAL is for local users ANN
1382 # The special name ALL is for ANN/FULL
1383 # The special name SYSOP is for ANN/SYSOP
1384 #
1385 sub import_chat
1386 {
1387         # are there any to do in this directory?
1388         return unless -d $chatimportfn;
1389         unless (opendir(DIR, $chatimportfn)) {
1390                 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1391                 Log('msg', "can\'t open $chatimportfn $!");
1392                 return;
1393         } 
1394
1395         my @names = readdir(DIR);
1396         closedir(DIR);
1397         my $name;
1398         foreach $name (@names) {
1399                 next if $name =~ /^\./;
1400                 my $splitit = $name =~ /^split/;
1401                 my $fn = "$chatimportfn/$name";
1402                 next unless -f $fn;
1403                 unless (open(MSG, $fn)) {
1404                         dbg("can\'t open import file $fn $!") if isdbg('msg');
1405                         Log('msg', "can\'t open import file $fn $!");
1406                         unlink($fn);
1407                         next;
1408                 }
1409                 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1410                 close(MSG);
1411                 unlink($fn);
1412
1413                 my @cat = split /\./, $name;
1414                 my $target = uc $cat[0];
1415
1416                 foreach my $text (@msg) {
1417                         next unless $text && $text !~ /^\s*#/;
1418                         if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1419                                 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1420                                 if ($target ne 'LOCAL') {
1421                                         send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1422                                 } else {
1423                                         Log('ann', 'LOCAL', $main::mycall, $text);
1424                                         DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1425                                 }
1426                         } else {
1427                                 my $msgid = nextchatmsgid();
1428                                 $text = "#$msgid $text";
1429                                 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
1430                         }
1431                 }
1432         }
1433 }
1434
1435 1;
1436 __END__