ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/metaserver2.ext
Revision: 1.4
Committed: Thu Nov 8 19:43:24 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
update copyrights and other minor stuff to deliantra

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     our $UPDATE_METASERVER2 = Event->timer (
13     reentrant => 0,
14 root 1.3 after => 37,
15 root 1.1 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 root 1.4 "User-Agent: Deliantra Server (+http://www.deliantra.net/)\015\012",
64 root 1.1 "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