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.2 by root, Sun Sep 9 20:26:48 2007 UTC vs.
Revision 1.7 by root, Thu Apr 29 07:52:02 2010 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 => 0,
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 => 2000,
37 cs_version => cf::VERSION_CS, 31 cs_version => 2000,
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 $content .= "\015\012"; # for good form 39 # this is a bit hacky, but hey, invoking LWP on something so trivial feels like a sin
46 40
47 # this is a bit hacky, but hey, invoking LWP on something so trivial feels like a sin 41 for my $url (@{ $cf::CFG{metaserver2_urls} || [] }) {
42 $url = new URI $url
43 or next;
44 $url->scheme eq "http"
45 or next;
48 46
49 for my $url (@{ $cf::CFG{metaserver2_urls} || [] }) { 47 my $socket = new Coro::Socket
50 $url = new URI $url 48 Timeout => 60,
51 or next; 49 PeerAddr => $url->host_port,
52 $url->scheme eq "http" 50 LocalAddr => $cf::CFG{metaserver2_serveraddr}
53 or next; 51 or (cf::info "$url: connection error: $!"), next;
54 52
55 my $socket = new Coro::Socket 53 syswrite $socket, join "",
56 Timeout => 60, 54 "POST ", $url->path, " HTTP/1.0\015\012",
57 PeerAddr => $url->host_port, 55 "Host: ", $url->host, "\015\012",
58 LocalAddr => $cf::CFG{metaserver2_serveraddr} 56 "Content-Type: application/x-www-form-urlencoded\015\012",
59 or (warn "$url: connection error: $!"), next; 57 "User-Agent: Deliantra Server (+http://www.deliantra.net/)\015\012",
58 "Content-Length: ", length $content, "\015\012",
59 "\015\012",
60 $content
61 ;
60 62
61 syswrite $socket, join "", 63 shutdown $socket, 1;
62 "POST ", $url->path, " HTTP/1.0\015\012",
63 "Host: ", $url->host, "\015\012",
64 "Content-Type: application/x-www-form-urlencoded\015\012",
65 "User-Agent: Crossfire TRT Server (http://crossfire.schmorp.de)\015\012",
66 "Content-Length: ", length $content, "\015\012",
67 "\015\012",
68 $content
69 ;
70 64
71 shutdown $socket, 1; 65 my $response = $socket->readline (undef);
72 66
73 my $response = $socket->readline (undef); 67 unless ($response =~ /^HTTP\/[0-9.]+\s+200\s+/) {
68 cf::info "$url: $response\n";
69 }
70 }
71};
74 72
75 unless ($response =~ /^HTTP\/[0-9.]+\s+200\s+/) {
76 warn "$url: $response\n";
77 }
78 }
79 },
80);
81

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines