line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
32199
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
106
|
|
3
|
|
|
|
|
|
|
package Net::OTServ; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Retrieve status information about Open Tibia Servers |
6
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
132
|
|
9
|
2
|
|
|
2
|
|
1177
|
use IO::Socket; |
|
2
|
|
|
|
|
42089
|
|
|
2
|
|
|
|
|
7
|
|
10
|
2
|
|
|
2
|
|
1983
|
use IO::Socket::Timeout; |
|
2
|
|
|
|
|
10339
|
|
|
2
|
|
|
|
|
10
|
|
11
|
2
|
|
|
2
|
|
808
|
use XML::Hash::XS; |
|
2
|
|
|
|
|
1383
|
|
|
2
|
|
|
|
|
338
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Net::OTServ - Retrieve status information about Open Tibia Servers |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Net::OTServ; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $status = Net::OTServ::status("127.0.0.1", 7171); |
27
|
|
|
|
|
|
|
print "We got $status->{players}{online} players online!\n" |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Open Tibia servers offer a XML interface to query online count, client version and other information. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS AND ARGUMENTS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 4 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item status($ip [, $port]) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Retrieves the status of specified OTServ as a hash reference. If C<$port> is omitted, the default 7171 is assumed. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub status { |
45
|
4
|
|
|
4
|
1
|
1072320
|
my $ip = shift; |
46
|
4
|
|
100
|
|
|
19
|
my $port = shift || 7171; |
47
|
4
|
|
|
|
|
7
|
my $timeout = 1; |
48
|
|
|
|
|
|
|
|
49
|
4
|
100
|
|
|
|
40
|
my $ot = IO::Socket::INET->new( |
50
|
|
|
|
|
|
|
PeerAddr => $ip, |
51
|
|
|
|
|
|
|
PeerPort => $port, |
52
|
|
|
|
|
|
|
Proto => 'tcp', |
53
|
|
|
|
|
|
|
Timeout => $timeout, # connection timeout |
54
|
|
|
|
|
|
|
) or croak "OTServ at $ip:$port is offline."; |
55
|
2
|
|
|
|
|
174408
|
IO::Socket::Timeout->enable_timeouts_on($ot); |
56
|
2
|
|
|
|
|
495
|
$ot->read_timeout($timeout); |
57
|
2
|
|
|
|
|
97
|
$ot->write_timeout($timeout); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
69
|
$ot->write("\x06\x00\xFF\xFF\x69\x6E\x66\x6F"); |
60
|
2
|
|
|
|
|
218
|
my $xml; $ot->recv($xml, 1024); |
|
2
|
|
|
|
|
19
|
|
61
|
2
|
50
|
|
|
|
123112
|
$xml or croak "Server at $ip:$port doesn't reply."; |
62
|
2
|
|
|
|
|
6
|
my $status; eval { $status = xml2hash $xml }; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
421
|
|
63
|
2
|
100
|
66
|
|
|
54
|
$status and !$@ |
64
|
|
|
|
|
|
|
or croak "Server at $ip:$port doesn't reply in XML."; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
107
|
return $status; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |