#! perl # metaserver2 reports use URI; use URI::Escape (); use Coro::Socket; $cf::CFG{metaserver2_urls} or return; 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 => 2000, cs_version => 2000, ); 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 (cf::info "$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+/) { cf::info "$url: $response\n"; } } };