line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Partty; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Class::Accessor::Fast'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
991
|
|
6
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ sock host port select /); |
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3993
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
106
|
|
10
|
1
|
|
|
1
|
|
1815
|
use IO::Select; |
|
1
|
|
|
|
|
2087
|
|
|
1
|
|
|
|
|
56
|
|
11
|
1
|
|
|
1
|
|
1243
|
use IO::Socket::Telnet; |
|
1
|
|
|
|
|
37175
|
|
|
1
|
|
|
|
|
13
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $DefaultOpts = { |
14
|
|
|
|
|
|
|
host => 'www.partty.org', |
15
|
|
|
|
|
|
|
port => 2750, |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
1
|
|
my($class, %opts) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
for my $opt (qw/ sock host port /) { |
24
|
0
|
|
0
|
|
|
|
$self->{$opt} = delete $opts{$opt} || $DefaultOpts->{$opt}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->{select} = IO::Select->new; |
28
|
0
|
0
|
|
|
|
|
$self->{sock} or $self->_sock_open; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _sock_open { |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
0
|
0
|
|
|
|
|
$self->{sock} = IO::Socket::Telnet->new( |
36
|
|
|
|
|
|
|
PeerAddr => $self->host, |
37
|
|
|
|
|
|
|
PeerPort => $self->port, |
38
|
|
|
|
|
|
|
Proto => 'tcp', |
39
|
|
|
|
|
|
|
) or croak $!; |
40
|
0
|
|
|
|
|
|
$self->select->add($self->{sock}); |
41
|
0
|
|
|
|
|
|
$self->{sock}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _sock_close { |
45
|
0
|
|
|
0
|
|
|
my $self = shift; |
46
|
0
|
0
|
|
|
|
|
return unless $self->{sock}; |
47
|
0
|
|
|
|
|
|
close $self->{sock}; |
48
|
0
|
|
|
|
|
|
$self->select->remove($self->{sock}); |
49
|
0
|
|
|
|
|
|
delete $self->{sock}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _send_uint8 { |
53
|
0
|
|
|
0
|
|
|
my($self, $int) = @_; |
54
|
0
|
|
|
|
|
|
my $data = pack 'C', $int; |
55
|
0
|
|
|
|
|
|
$self->sock->send($data); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
sub _send_uint16 { |
58
|
0
|
|
|
0
|
|
|
my($self, $int) = @_; |
59
|
0
|
|
|
|
|
|
my $data = pack 'n', $int; |
60
|
0
|
|
|
|
|
|
$self->sock->send($data); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub connect { |
64
|
0
|
|
|
0
|
0
|
|
my($self, %opts) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my @params = qw( message session_name writable_password readonly_password ); |
67
|
0
|
|
|
|
|
|
my @error; |
68
|
0
|
|
|
|
|
|
for my $param (@params) { |
69
|
0
|
0
|
|
|
|
|
push @error, $param unless exists $opts{$param}; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
croak join(', ', @error) . ' parameters is required.' if @error; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
croak 'session time out' unless $self->can_write(10); |
74
|
0
|
|
|
|
|
|
$self->sock->send('Partty!'); |
75
|
0
|
|
|
|
|
|
$self->_send_uint8(2); |
76
|
0
|
|
|
|
|
|
for my $param (@params) { |
77
|
0
|
|
|
|
|
|
$self->_send_uint16(length $opts{$param}); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
for my $param (@params) { |
80
|
0
|
|
|
|
|
|
$self->sock->send($opts{$param}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
croak 'session time out' unless $self->can_read(10); |
85
|
0
|
|
|
|
|
|
my $sock = $self->sock; |
86
|
0
|
|
|
|
|
|
my $buf; |
87
|
0
|
|
|
|
|
|
$self->sock->read($buf, 2); |
88
|
0
|
|
|
|
|
|
my $retcode = unpack 'n', $buf; |
89
|
0
|
|
|
|
|
|
$self->sock->read($buf, 2); |
90
|
0
|
|
|
|
|
|
my $retmessage_len = unpack 'n', $buf; |
91
|
0
|
|
|
|
|
|
$self->sock->read(my $retmessage, $retmessage_len); |
92
|
0
|
0
|
|
|
|
|
croak $retmessage if $retcode; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub can_read { |
96
|
0
|
|
|
0
|
0
|
|
my($self, $time) = @_; |
97
|
0
|
|
|
|
|
|
$self->select->can_read($time); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub can_write { |
101
|
0
|
|
|
0
|
0
|
|
my($self, $time) = @_; |
102
|
0
|
|
|
|
|
|
$self->select->can_write($time); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
package # |
107
|
|
|
|
|
|
|
IO::Socket::Telnet; |
108
|
|
|
|
|
|
|
sub sb { |
109
|
0
|
|
|
0
|
0
|
|
my($self, $cmd, $opt) = @_; |
110
|
0
|
|
|
|
|
|
$self->send(chr(255) . chr(250) . $cmd . $opt . chr(255) . chr(240)); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
__END__ |