fix talk command.
[spider.git] / cmd / talk.pl
1 #
2 # The talk command (improved)
3 #
4 # Copyright (c) 1998 Dirk Koopman G1TLH
5 #
6 #
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 || $self->inscript;
16
17 # analyse the line there are four situations...
18 # 1) talk call
19 # 2) talk call <text>
20 # 3) talk call>node  **via ignored
21 # 4) talk call>node text **ditto
22 #
23
24 # via is deprecated / ignored
25 $inline =~ s/(?:\s*>([A-Za-z0-9\-]+))\s*//;
26
27 ($to, $line) = $inline =~ /^\s*([A-Za-z0-9\-]+)\s*(.*)?$/;
28
29 #$DB::single = 1;
30
31 return (1, $self->msg('e8')) unless $to;
32
33 $to = uc $to;
34
35 return (1, $self->msg('e22', $to)) unless is_callsign($to);
36 return (1, $self->msg('e28')) unless $self->isregistered || $to eq $main::myalias;
37
38 #$via = uc $via if $via;
39 #my $call = $via || $to;
40 #my $clref = Route::get($call);     # try an exact call
41 #my $dxchan = $clref->dxchan if $clref;
42 #push @out, $self->msg('e7', $call) unless $dxchan;
43
44 my $call = $to;
45
46 #$DB::single = 1;
47
48 # default the 'via'
49 $via ||= '*';
50
51 my $ipaddr = DXCommandmode::alias_localhost($self->hostname || '127.0.0.1');
52
53 # if there is a line send it, otherwise add this call to the talk list
54 # and set talk mode for command mode
55 my @bad;
56 if (@bad = BadWords::check($line)) {
57         $self->badcount(($self->badcount||0) + @bad);
58         LogDbg('DXCommand', "$self->{call} swore: $line (with words:" . join(',', @bad) . ")");
59 }
60
61 my $dxchan;
62
63 if ($line) {
64         Log('talk', $to, $from, '>' . ($via || ($dxchan && $dxchan->call) || '*'), $line);
65         #$main::me->normal(DXProt::pc93($to, $self->call, $via, $line, undef, $ipaddr));
66         $self->send_talks($to, $line);
67 } else {
68         my $s = $to;
69         my $ref = $self->talklist;
70         if ($ref) {
71                 unless (grep { $_ eq $s } @$ref) {
72                         $main::me->normal(DXProt::pc93($to, $self->call, $via, $self->msg('talkstart'), undef,  $ipaddr));
73                         $self->state('talk');
74                         push @$ref, $s;
75                 }
76         } else { 
77                 $self->talklist([ $s ]);
78                 $main::me->normal(DXProt::pc93($to, $self->call, $via, $self->msg('talkstart'), undef, $ipaddr));
79                 push @out, $self->msg('talkinst');
80                 $self->state('talk');
81         }
82         Log('talk', $to, $from, '>' . ($via || ($dxchan && $dxchan->call) || '*'), $self->msg('talkstart'), undef, $ipaddr);
83         push @out, $self->talk_prompt;
84 }
85
86 return (1, @out);
87