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