my $time = shift;
my $retval;
- return("0s")
- if (!defined $time or $time !~ /\d+/ or $time <= 0);
+ return("NULL s") if (!defined $time or $time !~ /\d+/);
+
+ my $prefix = "";
+ if ($time < 0) {
+ $time = - $time;
+ $prefix = "- ";
+ }
my $s = int($time) % 60;
my $m = int($time / 60) % 60;
my $h = int($time / 3600) % 24;
my $d = int($time / 86400);
- $retval .= sprintf(" \002%d\002d", $d) if ($d != 0);
- $retval .= sprintf(" \002%d\002h", $h) if ($h != 0);
- $retval .= sprintf(" \002%d\002m", $m) if ($m != 0);
- $retval .= sprintf(" \002%d\002s", $s) if ($s != 0);
+ my @data;
+ push(@data, sprintf("\002%d\002d", $d)) if ($d != 0);
+ push(@data, sprintf("\002%d\002h", $h)) if ($h != 0);
+ push(@data, sprintf("\002%d\002m", $m)) if ($m != 0);
+ push(@data, sprintf("\002%d\002s", $s)) if ($s != 0 or !@data);
- return substr($retval, 1);
+ return $prefix.join(' ', @data);
}
###
# sort the hash list appropriately.
foreach (sort keys %files) {
my $file = $_;
- my @keys = sort keys %{$files{$file}};
+ my @keys = sort keys %{ $files{$file} };
my $i = scalar(@keys);
if ($i > 1) {
return 1;
}
+ &DEBUG("!exist $file") if (! -f $file);
+
return 1 unless ( -f $file);
if ($file =~ /idx/) {
- my $age = time() - (stat($file))[9];
- &DEBUG("stale: $age. (". &Time2String($age) .")");
+ my $age2 = time() - (stat($file))[9];
+ &VERB("stale: $age2. (". &Time2String($age2) .")",2);
}
- return 1 if (time() - (stat($file))[9] > $age*60*60*24);
+ $age *= 60*60*24 if ($age >= 0 and $age < 30);
+
+ return 1 if (time() - (stat($file))[9] > $age);
return 0;
}
# Usage: &makeHostMask($host);
sub makeHostMask {
- my ($host) = @_;
+ my ($host) = @_;
+ my $nu = "";
+
+ if ($host =~ s/^(\S+!\S+\@)//) {
+ &DEBUG("mHM: detected nick!user\@ for host arg; fixing");
+ $nu = $1;
+ }
if ($host =~ /^$mask{ip}$/) {
- return "$1.$2.$3.*";
+ return $nu."$1.$2.$3.*";
}
my @array = split(/\./, $host);
- return $host if (scalar @array <= 3);
- return "*.".join('.',@{array}[1..$#array]);
+ return $nu.$host if (scalar @array <= 3);
+ return $nu."*.".join('.',@{array}[1..$#array]);
}
# Usage: &makeRandom(int);
return 0 if ( -f $file{PID});
}
+sub mkcrypt {
+ my($str) = @_;
+ my $salt = join '',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64];
+
+ return crypt($str, $salt);
+}
+
+sub closeStats {
+ return unless (&getChanConfList("ircTextCounters"));
+
+ foreach (keys %cmdstats) {
+ my $type = $_;
+ my $i = &dbGet("stats", "counter", "nick=".&dbQuote($type).
+ " AND type='cmdstats'");
+ $i += $cmdstats{$type};
+
+ &dbReplace("stats",
+ (nick => $type, type => "cmdstats", counter => $i)
+ );
+ }
+}
+
1;