--- deliantra/server/ext/metaserver2.ext 2007/09/09 20:26:48 1.2 +++ deliantra/server/ext/metaserver2.ext 2007/11/14 08:09:46 1.5 @@ -9,73 +9,64 @@ $cf::CFG{metaserver2_urls} or return; -our $UPDATE_METASERVER2 = Event->timer ( - reentrant => 0, - after => 0, - interval => 299, # crossfire itself uses 60something as interval - hard => 1, - data => cf::WF_AUTOCANCEL, - cb => Coro::unblock_sub { - my %form = ( - hostname => $cf::CFG{metaserver2_hostname}, - port => $cf::CFG{metaserver2_port}, - - html_comment => $cf::CFG{metaserver2_html_comment}, - text_comment => $cf::CFG{metaserver2_text_comment}, - flags => $cf::CFG{metaserver2_flags} || "K", - archbase => $cf::CFG{archbase} || "TRT", - mapbase => $cf::CFG{mapbase} || "TRT", - codebase => $cf::CFG{codebase} || "TRT", - - num_players => cf::player::num_playing, - in_bytes => 0, # no can do - out_bytes => 0, # no can do - uptime => time - $cf::UPTIME, - - version => cf::VERSION, - sc_version => cf::VERSION_SC, - cs_version => cf::VERSION_CS, - ); - - my $content = - join "&", - map "$_=" . (URI::Escape::uri_escape_utf8 $form{$_}), - keys %form; - - $content .= "\015\012"; # for good form - - # this is a bit hacky, but hey, invoking LWP on something so trivial feels like a sin - - for my $url (@{ $cf::CFG{metaserver2_urls} || [] }) { - $url = new URI $url - or next; - $url->scheme eq "http" - or next; - - my $socket = new Coro::Socket - Timeout => 60, - PeerAddr => $url->host_port, - LocalAddr => $cf::CFG{metaserver2_serveraddr} - or (warn "$url: connection error: $!"), next; - - syswrite $socket, join "", - "POST ", $url->path, " HTTP/1.0\015\012", - "Host: ", $url->host, "\015\012", - "Content-Type: application/x-www-form-urlencoded\015\012", - "User-Agent: Crossfire TRT Server (http://crossfire.schmorp.de)\015\012", - "Content-Length: ", length $content, "\015\012", - "\015\012", - $content - ; - - shutdown $socket, 1; - - my $response = $socket->readline (undef); - - unless ($response =~ /^HTTP\/[0-9.]+\s+200\s+/) { - warn "$url: $response\n"; - } +our $UPDATE_METASERVER2 = cf::periodic 299, Coro::unblock_sub { + my %form = ( + hostname => $cf::CFG{metaserver2_hostname}, + port => $cf::CFG{metaserver2_port}, + + html_comment => $cf::CFG{metaserver2_html_comment}, + text_comment => $cf::CFG{metaserver2_text_comment}, + flags => $cf::CFG{metaserver2_flags} || "K", + archbase => $cf::CFG{archbase} || "TRT", + mapbase => $cf::CFG{mapbase} || "TRT", + codebase => $cf::CFG{codebase} || "TRT", + + num_players => cf::player::num_playing, + in_bytes => 0, # no can do + out_bytes => 0, # no can do + uptime => time - $cf::UPTIME, + + version => cf::VERSION, + sc_version => cf::VERSION_SC, + cs_version => cf::VERSION_CS, + ); + + my $content = + join "&", + map "$_=" . (URI::Escape::uri_escape_utf8 $form{$_}), + keys %form; + + # this is a bit hacky, but hey, invoking LWP on something so trivial feels like a sin + + for my $url (@{ $cf::CFG{metaserver2_urls} || [] }) { + $url = new URI $url + or next; + $url->scheme eq "http" + or next; + + my $socket = new Coro::Socket + Timeout => 60, + PeerAddr => $url->host_port, + LocalAddr => $cf::CFG{metaserver2_serveraddr} + or (warn "$url: connection error: $!"), next; + + syswrite $socket, join "", + "POST ", $url->path, " HTTP/1.0\015\012", + "Host: ", $url->host, "\015\012", + "Content-Type: application/x-www-form-urlencoded\015\012", + "User-Agent: Deliantra Server (+http://www.deliantra.net/)\015\012", + "Content-Length: ", length $content, "\015\012", + "\015\012", + $content + ; + + shutdown $socket, 1; + + my $response = $socket->readline (undef); + + unless ($response =~ /^HTTP\/[0-9.]+\s+200\s+/) { + warn "$url: $response\n"; } - }, -); + } +};