ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/metaserver2.ext
Revision: 1.5
Committed: Wed Nov 14 08:09:46 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, rel-2_52, rel-2_53, rel-2_32, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, rel-2_43, rel-2_42, rel-2_41
Changes since 1.4: +59 -66 lines
Log Message:
switch from Event to EV

File Contents

# Content
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