line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SRCDS::Queries; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
93240
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
4
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
64
|
|
5
|
3
|
|
|
3
|
|
1870
|
use version; our $VERSION = qv('0.0.5'); |
|
3
|
|
|
|
|
5917
|
|
|
3
|
|
|
|
|
17
|
|
6
|
3
|
|
|
3
|
|
249
|
use Carp qw(croak); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
183
|
|
7
|
3
|
|
|
3
|
|
2895
|
use IO::Socket::INET; |
|
3
|
|
|
|
|
56386
|
|
|
3
|
|
|
|
|
23
|
|
8
|
3
|
|
|
3
|
|
4172
|
use IO::Select; |
|
3
|
|
|
|
|
4959
|
|
|
3
|
|
|
|
|
138
|
|
9
|
3
|
|
|
3
|
|
18
|
use base qw(Net::SRCDS::Queries::Parser); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2017
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# implemented queries |
12
|
|
|
|
|
|
|
# see http://developer.valvesoftware.com/wiki/Source_Server_Queries |
13
|
|
|
|
|
|
|
# for all queries. |
14
|
|
|
|
|
|
|
# |
15
|
3
|
|
|
3
|
|
15
|
use constant GETCHALLENGE => "\xFF\xFF\xFF\xFF\x57"; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
170
|
|
16
|
3
|
|
|
3
|
|
15
|
use constant A2S_INFO => "\xFF\xFF\xFF\xFFTSource Engine Query\0"; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
150
|
|
17
|
3
|
|
|
3
|
|
15
|
use constant A2S_PLAYER => "\xFF\xFF\xFF\xFF\x55"; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
147
|
|
18
|
3
|
|
|
3
|
|
15
|
use constant A2S_RULES => "\xFF\xFF\xFF\xFF\x56"; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
128
|
|
19
|
3
|
|
|
3
|
|
14
|
use constant MAX_SOCKBUF => 65535; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2331
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
2
|
|
|
2
|
1
|
346
|
my( $class, %args ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $socket = IO::Socket::INET->new( |
25
|
|
|
|
|
|
|
Proto => 'udp', |
26
|
|
|
|
|
|
|
Blocking => 0, |
27
|
2
|
50
|
50
|
|
|
29
|
LocalPort => $args{LocalPort} || 0, |
28
|
|
|
|
|
|
|
) or croak "cannot bind socket : $!"; |
29
|
2
|
|
|
|
|
488
|
my $select = IO::Select->new($socket); |
30
|
|
|
|
|
|
|
my $self = { |
31
|
|
|
|
|
|
|
socket => $socket, |
32
|
|
|
|
|
|
|
select => $select, |
33
|
|
|
|
|
|
|
servers => [], |
34
|
|
|
|
|
|
|
timeout => $args{timeout} || 3, |
35
|
|
|
|
|
|
|
encoding => $args{encoding} || undef, |
36
|
2
|
|
50
|
|
|
175
|
}; |
|
|
|
50
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->{float_order} = |
38
|
2
|
50
|
|
|
|
13
|
unpack( 'H*', pack( 'f', 1.05 ) ) eq '6666863f' ? 0 : 1; |
39
|
2
|
|
|
|
|
10
|
bless $self, $class; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_server { |
43
|
0
|
|
|
0
|
1
|
0
|
my( $self, $addr, $port ) = @_; |
44
|
0
|
|
|
|
|
0
|
push @{ $self->{servers} }, { addr => $addr, port => $port }; |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_all { |
48
|
0
|
|
|
0
|
1
|
0
|
my($self) = @_; |
49
|
0
|
|
|
|
|
0
|
my $select = $self->{select}; |
50
|
0
|
|
|
|
|
0
|
my $timeout = $self->{timeout}; |
51
|
0
|
|
|
|
|
0
|
for my $s ( @{ $self->{servers} } ) { |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
|
|
0
|
my $dest = sockaddr_in $s->{port}, inet_aton $s->{addr}; |
53
|
0
|
|
|
|
|
0
|
$self->send_a2s_info($dest); |
54
|
0
|
|
|
|
|
0
|
$self->send_challenge($dest); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
0
|
my $finished = {}; |
57
|
0
|
|
|
|
|
0
|
LOOP: while (1) { |
58
|
0
|
|
|
|
|
0
|
my @ready = $select->can_read($timeout); |
59
|
0
|
|
|
|
|
0
|
for my $fh (@ready) { |
60
|
0
|
|
|
|
|
0
|
my $sender = $fh->recv( my $buf, MAX_SOCKBUF ); |
61
|
0
|
|
|
|
|
0
|
my( $port, $addr ) = sockaddr_in $sender; |
62
|
0
|
|
|
|
|
0
|
my $server = sprintf "%s:%s", inet_ntoa($addr), $port; |
63
|
0
|
|
|
|
|
0
|
my $result = $self->parse_packet( $buf, $server, $sender ); |
64
|
0
|
|
|
|
|
0
|
my $sr = $self->{results}->{$server}; |
65
|
0
|
0
|
0
|
|
|
0
|
if ( exists $sr->{player} and exists $sr->{rules} ) { |
66
|
0
|
|
|
|
|
0
|
$finished->{$server}++; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
last LOOP |
69
|
0
|
0
|
|
|
|
0
|
if scalar keys %{$finished} >= scalar @{ $self->{servers} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
# exit loop when you get nothing |
72
|
0
|
0
|
|
|
|
0
|
unless (@ready) { |
73
|
0
|
|
|
|
|
0
|
warn "no ready\n"; |
74
|
0
|
|
|
|
|
0
|
last LOOP; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
return $self->{results}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub send_challenge { |
81
|
1
|
|
|
1
|
1
|
1240
|
my( $self, $dest ) = @_; |
82
|
1
|
|
|
|
|
3
|
my $socket = $self->{socket}; |
83
|
1
|
|
|
|
|
9
|
$socket->send( GETCHALLENGE, 0, $dest ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub send_a2s_info { |
87
|
1
|
|
|
1
|
1
|
535113
|
my( $self, $dest ) = @_; |
88
|
1
|
|
|
|
|
33
|
my $socket = $self->{socket}; |
89
|
1
|
|
|
|
|
24
|
$socket->send( A2S_INFO, 0, $dest ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub send_a2s_player { |
93
|
1
|
|
|
1
|
1
|
1165
|
my( $self, $dest, $cnum ) = @_; |
94
|
1
|
|
|
|
|
4
|
my $socket = $self->{socket}; |
95
|
1
|
|
|
|
|
11
|
$socket->send( A2S_PLAYER . $cnum, 0, $dest ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub send_a2s_rules { |
99
|
1
|
|
|
1
|
1
|
3571
|
my( $self, $dest, $cnum ) = @_; |
100
|
1
|
|
|
|
|
4
|
my $socket = $self->{socket}; |
101
|
1
|
|
|
|
|
11
|
$socket->send( A2S_RULES . $cnum, 0, $dest ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub get_result { |
105
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
106
|
0
|
|
|
|
|
|
return $self->{results}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |