+ my $now = [Time::HiRes::gettimeofday];
+
+ # First of all, close any surveys that are due.
+ for my $sport (keys %active_surveys) {
+ my $age = Time::HiRes::tv_interval($active_surveys{$sport}{start}, $now);
+ if ($age > $Config::survey_time && $active_surveys{$sport}{active}) {
+ print "Survey for '" . $Config::access_list[$active_surveys{$sport}{entry}]->{name} . "'/" .
+ $active_surveys{$sport}{dport} . ": " . $active_surveys{$sport}{num} . " active servers.\n";
+ $active_surveys{$sport}{active} = 0;
+
+ # (re)connect to the database if needed
+ if (!defined($dbh) || !$dbh->ping) {
+ $dbh = nms::db_connect();
+ $q = $dbh->prepare("INSERT INTO mbd_log (ts,game,port,description,active_servers) VALUES (CURRENT_TIMESTAMP,?,?,?,?)")
+ or die "Couldn't prepare query";
+ }
+ $q->execute($active_surveys{$sport}{entry}, $active_surveys{$sport}{dport}, $Config::access_list[$active_surveys{$sport}{entry}]->{name}, $active_surveys{$sport}{num});
+ }
+ if ($age > $Config::survey_time * 3.0) {
+ delete $active_surveys{$sport};
+ }
+ }
+