fixed routing talk messages
[spider.git] / cmd / talk.pl
1 #
2 # The talk command
3 #
4 # Copyright (c) 1998 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my @argv = split /\s+/, $line;  # generate an argv
11 my $to = uc $argv[0];
12 my $via;
13 my $from = $self->call();
14 my @out;
15
16 # have we a callsign and some text?
17 return (1, $self->msg('e8')) if @argv < 2;
18
19 if ($argv[1] eq '>') {
20         $via = uc $argv[2];
21         $line =~ s/^$argv[0]\s+>\s+$argv[2]\s*//;
22 } else {
23         $line =~ s/^$argv[0]\s*//;
24 }
25
26 my $call = $via ? $via : $to;
27 my $ref = DXCluster->get($call);
28
29 # if we haven't got an explicit via and we can't see them, try their node
30 unless ($ref || $via) {
31         my $user = DXUser->get($call);
32         $ref = DXCluster->get_exact($user->node) if $user;
33         if ($ref) {
34                 $via = $user->node;
35                 push @out, "trying via $via..";
36         }
37 }
38 return (1, "$call not visible on the cluster") if !$ref;
39
40 # change ^ into : for transmission
41 $line =~ s/\^/:/og;
42
43 my $dxchan = DXCommandmode->get($to); # is it for us?
44 if ($dxchan && $dxchan->is_user) {
45         $dxchan->send("$to de $from $line") if $dxchan->talk;
46         Log('talk', $to, $from, $main::mycall, $line);
47 } else {
48         $line =~ s/\^//og;                      # remove any ^ characters
49         my $prot = DXProt::pc10($from, $to, $via, $line);
50         DXProt::route(undef,$via?$via:$to, $prot);
51         Log('talk', $to, $from, $via?$via:$main::mycall, $line);
52 }
53
54 return (1, @out);
55