62198627e3873b463825654399eafc39bee3adc3
[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 return (1, $self->msg('e8')) unless $to;
30
31 $to = uc $to;
32
33 return (1, $self->msg('e22', $to)) unless is_callsign($to);
34 return (1, $self->msg('e28')) unless $self->isregistered || $to eq $main::myalias;
35
36 #$via = uc $via if $via;
37 #my $call = $via || $to;
38 #my $clref = Route::get($call);     # try an exact call
39 #my $dxchan = $clref->dxchan if $clref;
40 #push @out, $self->msg('e7', $call) unless $dxchan;
41
42 my $call = $to;
43
44 #$DB::single = 1;
45
46 # default the 'via'
47 $via ||= '*';
48
49 my $ipaddr = DXCommandmode::alias_localhost($self->hostname || '127.0.0.1');
50
51 # if there is a line send it, otherwise add this call to the talk list
52 # and set talk mode for command mode
53 my @bad;
54 if (@bad = BadWords::check($line)) {
55         $self->badcount(($self->badcount||0) + @bad);
56         LogDbg('DXCommand', "$self->{call} swore: $line (with words:" . join(',', @bad) . ")");
57 }
58
59 my $dxchan;
60
61 if ($line) {
62         Log('talk', $to, $from, '>' . ($via || ($dxchan && $dxchan->call) || '*'), $line);
63         #$main::me->normal(DXProt::pc93($to, $self->call, $via, $line, undef, $ipaddr));
64         $self->send_talks($to, $line);
65 } else {
66         my $s = $to;
67         my $ref = $self->talklist;
68         if ($ref) {
69                 unless (grep { $_ eq $s } @$ref) {
70                         $main::me->normal(DXProt::pc93($to, $self->call, $via, $self->msg('talkstart'), undef,  $ipaddr));
71                         $self->state('talk');
72                         push @$ref, $s;
73                 }
74         } else { 
75                 $self->talklist([ $s ]);
76                 $main::me->normal(DXProt::pc93($to, $self->call, $via, $self->msg('talkstart'), undef, $ipaddr));
77                 push @out, $self->msg('talkinst');
78                 $self->state('talk');
79         }
80         Log('talk', $to, $from, '>' . ($via || ($dxchan && $dxchan->call) || '*'), $self->msg('talkstart'), undef, $ipaddr);
81         push @out, $self->talk_prompt;
82 }
83
84 return (1, @out);
85