ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/metaserver2.ext
Revision: 1.6
Committed: Thu Apr 8 19:31:22 2010 UTC (14 years, 1 month ago) by root
Branch: MAIN
Changes since 1.5: +2 -2 lines
Log Message:
new server protocol

File Contents

# User Rev Content
1 root 1.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 root 1.5 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 root 1.6 sc_version => 2000,
31     cs_version => 2000,
32 root 1.5 );
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 root 1.1 }
70 root 1.5 }
71     };
72 root 1.1