ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/metaserver2.ext
Revision: 1.3
Committed: Mon Sep 10 08:02:14 2007 UTC (16 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_2, rel-2_3
Changes since 1.2: +1 -3 lines
Log Message:
*** empty log message ***

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