1 |
#! perl |
2 |
|
3 |
# metaserver2 reports |
4 |
|
5 |
use URI; |
6 |
use URI::Escape (); |
7 |
use Coro::Socket; |
8 |
|
9 |
$cf::CFG{metaserver2_urls} |
10 |
or return; |
11 |
|
12 |
our $UPDATE_METASERVER2 = cf::periodic 299, Coro::unblock_sub { |
13 |
my %form = ( |
14 |
hostname => $cf::CFG{metaserver2_hostname}, |
15 |
port => $cf::CFG{metaserver2_port}, |
16 |
|
17 |
html_comment => $cf::CFG{metaserver2_html_comment}, |
18 |
text_comment => $cf::CFG{metaserver2_text_comment}, |
19 |
flags => $cf::CFG{metaserver2_flags} || "K", |
20 |
archbase => $cf::CFG{archbase} || "TRT", |
21 |
mapbase => $cf::CFG{mapbase} || "TRT", |
22 |
codebase => $cf::CFG{codebase} || "TRT", |
23 |
|
24 |
num_players => cf::player::num_playing, |
25 |
in_bytes => 0, # no can do |
26 |
out_bytes => 0, # no can do |
27 |
uptime => time - $cf::UPTIME, |
28 |
|
29 |
version => cf::VERSION, |
30 |
sc_version => cf::VERSION_SC, |
31 |
cs_version => cf::VERSION_CS, |
32 |
); |
33 |
|
34 |
my $content = |
35 |
join "&", |
36 |
map "$_=" . (URI::Escape::uri_escape_utf8 $form{$_}), |
37 |
keys %form; |
38 |
|
39 |
# this is a bit hacky, but hey, invoking LWP on something so trivial feels like a sin |
40 |
|
41 |
for my $url (@{ $cf::CFG{metaserver2_urls} || [] }) { |
42 |
$url = new URI $url |
43 |
or next; |
44 |
$url->scheme eq "http" |
45 |
or next; |
46 |
|
47 |
my $socket = new Coro::Socket |
48 |
Timeout => 60, |
49 |
PeerAddr => $url->host_port, |
50 |
LocalAddr => $cf::CFG{metaserver2_serveraddr} |
51 |
or (warn "$url: connection error: $!"), next; |
52 |
|
53 |
syswrite $socket, join "", |
54 |
"POST ", $url->path, " HTTP/1.0\015\012", |
55 |
"Host: ", $url->host, "\015\012", |
56 |
"Content-Type: application/x-www-form-urlencoded\015\012", |
57 |
"User-Agent: Deliantra Server (+http://www.deliantra.net/)\015\012", |
58 |
"Content-Length: ", length $content, "\015\012", |
59 |
"\015\012", |
60 |
$content |
61 |
; |
62 |
|
63 |
shutdown $socket, 1; |
64 |
|
65 |
my $response = $socket->readline (undef); |
66 |
|
67 |
unless ($response =~ /^HTTP\/[0-9.]+\s+200\s+/) { |
68 |
warn "$url: $response\n"; |
69 |
} |
70 |
} |
71 |
}; |
72 |
|