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