ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/metaserver2.ext
(Generate patch)

Comparing deliantra/server/ext/metaserver2.ext (file contents):
Revision 1.4 by root, Thu Nov 8 19:43:24 2007 UTC vs.
Revision 1.5 by root, Wed Nov 14 08:09:46 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines