| 1 | #$Id: hubcli.pm 998 2013-08-14 12:21:20Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/lib/Net/DirectConnect/hubcli.pm $ | ||||||||||||||||||||
| 2 | #reserved for future 8), but something works | ||||||||||||||||||||
| 3 | package #hide from cpan | ||||||||||||||||||||
| 4 | Net::DirectConnect::hubcli; | ||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | no strict qw(refs); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use warnings "NONFATAL" => "all"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | no if $] >= 5.017011, warnings => 'experimental::smartmatch'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Net::DirectConnect; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||
| 13 | 1 | our $VERSION = ( split( ' ', '$Revision: 998 $' ) )[1]; | |||||||||||||||||||
| 14 | 1 | ▶ | use base 'Net::DirectConnect'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||
| 18 | 0 | %$self = ( %$self,, @_ ); | |||||||||||||||||||
| 19 | #$self->baseinit(); | ||||||||||||||||||||
| 20 | 0 | $self->get_peer_addr(); | |||||||||||||||||||
| 21 | 0 | ▶ | $self->log( 'info', "[$self->{'number'}] Incoming client $self->{'host'}:$self->{'port'}" ) if $self->{'incoming'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | $self->{'parse'} ||= { | ||||||||||||||||||||
| 23 | 0 | ▶ | 'Supports' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 24 | #$self->supports_parse( $_[0], $self->{'NickList'}->{ $self->{'peernick'} } ); | ||||||||||||||||||||
| 25 | 0 | $self->supports_parse( $_[0], $self->{'peer_supports'} ); | |||||||||||||||||||
| 26 | }, | ||||||||||||||||||||
| 27 | 0 | ▶ | 'Key' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||
| 29 | 0 | ▶ | 'ValidateNick' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 30 | #$self->log('dev', 'denide', $_[0], Dumper $self->{'NickList'}), | ||||||||||||||||||||
| 31 | #!return $self->cmd('ValidateDenide') if exists $self->{'NickList'}{ $_[0] } and $self->{'NickList'}{ $_[0] }{'online'}; | ||||||||||||||||||||
| 32 | 0 | $self->{'peer_nick'} = $_[0]; | |||||||||||||||||||
| 33 | 0 | $self->{'NickList'}->{ $self->{'peer_nick'} } = $self->{'peer_supports'}; | |||||||||||||||||||
| 34 | 0 | $self->{'status'} = 'connected'; | |||||||||||||||||||
| 35 | 0 | $self->cmd('Hello'); | |||||||||||||||||||
| 36 | }, | ||||||||||||||||||||
| 37 | 0 | ▶ | 'Version' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 38 | 0 | $self->{'NickList'}{ $self->{'peer_nick'} }{'Version'} = $_[0]; | |||||||||||||||||||
| 39 | }, | ||||||||||||||||||||
| 40 | 0 | ▶ | 'GetNickList' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 41 | 0 | $self->cmd('NickList'); | |||||||||||||||||||
| 42 | 0 | $self->cmd('OpList'); | |||||||||||||||||||
| 43 | }, | ||||||||||||||||||||
| 44 | 0 | ▶ | 'MyINFO' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 45 | 0 | my ( $nick, $info ) = $_[0] =~ /\S+\s+(\S+)\s+(.*)/; | |||||||||||||||||||
| 46 | 0 | ▶ | return if $nick ne $self->{'peer_nick'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | $self->{'NickList'}{$nick}{'Nick'} = $nick; | |||||||||||||||||||
| 48 | 0 | $self->info_parse( $info, $self->{'NickList'}{$nick} ); | |||||||||||||||||||
| 49 | 0 | $self->{'NickList'}{$nick}{'online'} = 1; | |||||||||||||||||||
| 50 | }, | ||||||||||||||||||||
| 51 | 0 | ▶ | 'GetINFO' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 52 | 0 | my $to = shift; | |||||||||||||||||||
| 53 | }, | ||||||||||||||||||||
| 54 | 0 | ▶ | 'chatline' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 55 | 0 | $self->{'parent'}->rcmd( 'chatline', @_ ); | |||||||||||||||||||
| 56 | }, | ||||||||||||||||||||
| 57 | 0 | ▶ | }; | ||||||||||||||||||
|
Condition0%0/2
$self->{"parse"} ||= {"Supports", sub {
$self->supports_parse($_[0], $self->{"peer_supports"});
}
, "Key", sub {
}
, "ValidateNick", sub {
$self->{"peer_nick"} = $_[0];
$self->{"NickList"}{$self->{"peer_nick"}} = $self->{"peer_supports"};
$self->{"status"} = "connected";
$self->cmd("Hello");
}
, "Version", sub {
$self->{"NickList"}{$self->{"peer_nick"}}{"Version"} = $_[0];
}
, "GetNickList", sub {
$self->cmd("NickList");
$self->cmd("OpList");
}
, "MyINFO", sub {
my($nick, $info) = $_[0] =~ /\S+\s+(\S+)\s+(.*)/;
return if $nick ne $self->{"peer_nick"};
$self->{"NickList"}{$nick}{"Nick"} = $nick;
$self->info_parse($info, $self->{"NickList"}{$nick});
$self->{"NickList"}{$nick}{"online"} = 1;
}
, "GetINFO", sub {
my $to = shift();
}
, "chatline", sub {
$self->{"parent"}->rcmd("chatline", @_);
}
}
MC/DC0%0/1
$self->{"parse"} ||= {"Supports", sub {
$self->supports_parse($_[0], $self->{"peer_supports"});
}
, "Key", sub {
}
, "ValidateNick", sub {
$self->{"peer_nick"} = $_[0];
$self->{"NickList"}{$self->{"peer_nick"}} = $self->{"peer_supports"};
$self->{"status"} = "connected";
$self->cmd("Hello");
}
, "Version", sub {
$self->{"NickList"}{$self->{"peer_nick"}}{"Version"} = $_[0];
}
, "GetNickList", sub {
$self->cmd("NickList");
$self->cmd("OpList");
}
, "MyINFO", sub {
my($nick, $info) = $_[0] =~ /\S+\s+(\S+)\s+(.*)/;
return if $nick ne $self->{"peer_nick"};
$self->{"NickList"}{$nick}{"Nick"} = $nick;
$self->info_parse($info, $self->{"NickList"}{$nick});
$self->{"NickList"}{$nick}{"online"} = 1;
}
, "GetINFO", sub {
my $to = shift();
}
, "chatline", sub {
$self->{"parent"}->rcmd("chatline", @_);
}
}
$self->{"parse"}
Truth table0%0/2
A
A= $self->{"parse"}
| |||||||||||||||||||||
| 58 | $self->{'cmd'} ||= { | ||||||||||||||||||||
| 59 | 0 | ▶ | 'Lock' => sub { $self->sendcmd( 'Lock', $self->{'Lock'} ); }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 60 | 0 | ▶ | 'HubName' => sub { $self->sendcmd( 'HubName', $self->{'HubName'} ); }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 61 | 0 | ▶ | 'ValidateDenide' => sub { $self->sendcmd('ValidateDenide'); }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 62 | 0 | ▶ | 'Hello' => sub { $self->sendcmd( 'Hello', $self->{'peer_nick'} ); }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 63 | 0 | ▶ | 'NickList' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 64 | 0 | $self->sendcmd( 'NickList', join '$$', grep { !$self->{'NickList'}{$_}{'oper'} } keys %{ $self->{'NickList'} } ); | |||||||||||||||||||
| 65 | }, | ||||||||||||||||||||
| 66 | 0 | ▶ | 'OpList' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 67 | 0 | $self->sendcmd( 'OpList', join '$$', grep { $self->{'NickList'}{$_}{'oper'} } keys %{ $self->{'NickList'} } ); | |||||||||||||||||||
| 68 | }, | ||||||||||||||||||||
| 69 | 0 | ▶ | 'chatline_from' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 70 | 0 | my $from = shift; | |||||||||||||||||||
| 71 | #return if $self->{'_chatline_rec'}; | ||||||||||||||||||||
| 72 | 0 | for (@_) { | |||||||||||||||||||
| 73 | 0 | ▶ | return unless $self->{'socket'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | $self->log( 'dcdmp', "($self->{'number'}) we send [", "<$from> $_|", "]:", $self->{'socket'}->send("<$from> $_|"), $! ); | |||||||||||||||||||
| 75 | #$self->log('dbg', 'sleep', $self->{'min_chat_delay'}), | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||
| 78 | 0 | ▶ | 'chatline' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 79 | 0 | my ( $nick, $text ) = $_[0] =~ /^<([^>]+)> (.+)$/; | |||||||||||||||||||
| 80 | #$self->{'_chatline_rec'} = 1; | ||||||||||||||||||||
| 81 | 0 | $self->log( 'dbg', "[$self->{'number'}]", 'chatline Rstart', ); | |||||||||||||||||||
| 82 | $self->log( 'dbg', "[$self->{'number'}] to", $_->{'number'} ), | ||||||||||||||||||||
| 83 | #TO API | ||||||||||||||||||||
| 84 | $_->cmd( 'chatline_from', $self->{'peer_nick'}, $text ) | ||||||||||||||||||||
| 85 | 0 | ▶ | for grep { $_ and $_ ne $self } values( %{ $self->{'parent'}{'clients'} } ); | ||||||||||||||||||
|
Condition0%0/3
$_ && $_ ne $self
MC/DC0%0/2
$_ && $_ ne $self
$_
$_ ne $self
Truth table0%0/3
A && B
A= $_B= $_ ne $self
| |||||||||||||||||||||
| 86 | #$self->{'parent'}->rcmd('chatline_from', $self->{'peer_nick'}, $text); | ||||||||||||||||||||
| 87 | #delete $self->{'_chatline_rec'}; | ||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||
| 89 | 0 | ▶ | }; | ||||||||||||||||||
|
Condition0%0/2
$self->{"cmd"} ||= {"Lock", sub {
$self->sendcmd("Lock", $self->{"Lock"});
}
, "HubName", sub {
$self->sendcmd("HubName", $self->{"HubName"});
}
, "ValidateDenide", sub {
$self->sendcmd("ValidateDenide");
}
, "Hello", sub {
$self->sendcmd("Hello", $self->{"peer_nick"});
}
, "NickList", sub {
$self->sendcmd("NickList", join("\$\$", grep({not $self->{"NickList"}{$_}{"oper"};} keys %{$$self{"NickList"};})));
}
, "OpList", sub {
$self->sendcmd("OpList", join("\$\$", grep({$self->{"NickList"}{$_}{"oper"};} keys %{$$self{"NickList"};})));
}
, "chatline_from", sub {
my $from = shift();
foreach $_ (@_) {
return unless $self->{"socket"};
$self->log("dcdmp", qq(($self->{"number"}) we send [), "<$from> $_|", "]:", $self->{"socket"}->send("<$from> $_|"), $!);
};
}
, "chatline", sub {
my($nick, $text) = $_[0] =~ /^<([^>]+)> (.+)$/;
$self->log("dbg", qq[[$self->{"number"}]], "chatline Rstart");
$self->log("dbg", qq[[$self->{"number"}] to], $_->{"number"}), $_->cmd("chatline_from", $self->{"peer_nick"}, $text) foreach (grep {$_ and $_ ne $self;} values %{$$self{"parent"}{"clients"};});
}
}
MC/DC0%0/1
$self->{"cmd"} ||= {"Lock", sub {
$self->sendcmd("Lock", $self->{"Lock"});
}
, "HubName", sub {
$self->sendcmd("HubName", $self->{"HubName"});
}
, "ValidateDenide", sub {
$self->sendcmd("ValidateDenide");
}
, "Hello", sub {
$self->sendcmd("Hello", $self->{"peer_nick"});
}
, "NickList", sub {
$self->sendcmd("NickList", join("\$\$", grep({not $self->{"NickList"}{$_}{"oper"};} keys %{$$self{"NickList"};})));
}
, "OpList", sub {
$self->sendcmd("OpList", join("\$\$", grep({$self->{"NickList"}{$_}{"oper"};} keys %{$$self{"NickList"};})));
}
, "chatline_from", sub {
my $from = shift();
foreach $_ (@_) {
return unless $self->{"socket"};
$self->log("dcdmp", qq(($self->{"number"}) we send [), "<$from> $_|", "]:", $self->{"socket"}->send("<$from> $_|"), $!);
};
}
, "chatline", sub {
my($nick, $text) = $_[0] =~ /^<([^>]+)> (.+)$/;
$self->log("dbg", qq[[$self->{"number"}]], "chatline Rstart");
$self->log("dbg", qq[[$self->{"number"}] to], $_->{"number"}), $_->cmd("chatline_from", $self->{"peer_nick"}, $text) foreach (grep {$_ and $_ ne $self;} values %{$$self{"parent"}{"clients"};});
}
}
$self->{"cmd"}
Truth table0%0/2
A
A= $self->{"cmd"}
| |||||||||||||||||||||
| 90 | $self->{'handler_int'} ||= { | ||||||||||||||||||||
| 91 | 0 | ▶ | 'disconnect_aft' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 92 | #$self->{'NickList'}{$self->{'peer_nick'}}{'online'} = 0; | ||||||||||||||||||||
| 93 | 0 | delete $self->{'NickList'}{ $self->{'peer_nick'} }; | |||||||||||||||||||
| 94 | 0 | $self->log( 'dev', 'deleted', $self->{'peer_nick'}, Dumper $self->{'NickList'} ); | |||||||||||||||||||
| 95 | }, | ||||||||||||||||||||
| 96 | 0 | ▶ | }; | ||||||||||||||||||
|
Condition0%0/2
$self->{"handler_int"} ||= {"disconnect_aft", sub {
delete $self->{"NickList"}{$self->{"peer_nick"}};
$self->log("dev", "deleted", $self->{"peer_nick"}, Dumper($self->{"NickList"}));
}
}
MC/DC0%0/1
$self->{"handler_int"} ||= {"disconnect_aft", sub {
delete $self->{"NickList"}{$self->{"peer_nick"}};
$self->log("dev", "deleted", $self->{"peer_nick"}, Dumper($self->{"NickList"}));
}
}
$self->{"handler_int"}
Truth table0%0/2
A
A= $self->{"handler_int"}
| |||||||||||||||||||||
| 97 | 0 | $self->{'sendbuf'} = 1; | |||||||||||||||||||
| 98 | 0 | $self->cmd('Lock'); | |||||||||||||||||||
| 99 | 0 | $self->{'sendbuf'} = 0; | |||||||||||||||||||
| 100 | 0 | $self->cmd('HubName'); | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | 1 | 1; | |||||||||||||||||||