5. fix talkmode so that it only does 'via' PC10s when it really needs to.
[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, $inline) = @_;
10 my $to;
11 my $via;
12 my $line;
13 my $from = $self->call;
14 my @out;
15 return (1, $self->msg('e5')) if $self->remotecmd;
16
17 # analyse the line there are four situations...
18 # 1) talk call
19 # 2) talk call <text>
20 # 3) talk call>node 
21 # 4) talk call>node text
22 #
23
24 ($to, $via, $line) = $inline =~ /^\s*([A-Za-z0-9\-]+)\s*>([A-Za-z0-9\-]+)(.*)$/;
25 if ($via) {
26         $line =~ s/\s+// if $line;
27 } else {
28         ($to, $line) = split /\s+/, $inline, 2;  
29 }
30
31 $to = uc $to if $to;
32 $via = uc $via if $via;
33 my $call = $via ? $via : $to;
34 my $clref = DXCluster->get_exact($call);     # try an exact call
35 my $dxchan = $clref->dxchan if $clref;
36 return (1, $self->msg('e7', $call)) unless $dxchan;
37
38 # if there is a line send it, otherwise add this call to the talk list
39 # and set talk mode for command mode
40 if ($line) {
41         $dxchan->talk($self->call, $to, $via, $line) if $dxchan;
42 } else {
43         my $s = $to;
44         $s .= ">$via" if $via;
45         my $ref = $self->talklist;
46         if ($ref) {
47                 unless (grep { $_ eq $s } @$ref) {
48                         $dxchan->talk($self->call, $to, $via, $self->msg('talkstart'));
49                         $self->state('talk');
50                         push @$ref, $s;
51                 }
52         } else { 
53                 $self->talklist([ $s ]);
54                 $dxchan->talk($self->call, $to, $via, $self->msg('talkstart'));
55                 push @out, $self->msg('talkinst');
56                 $self->state('talk');
57         }
58         push @out, $self->talk_prompt;
59 }
60
61 return (1, @out);
62