changeset 17:bef72aa85f2b

Ignoring bad data with 2^32 second finish times
author Dominic Cleal <dominic@computerkb.co.uk>
date Sat, 06 Dec 2008 16:49:36 +0000
parents e238f28f774a
children 10587dbd634b
files skillbot.pl
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/skillbot.pl	Sat Dec 06 16:46:52 2008 +0000
+++ b/skillbot.pl	Sat Dec 06 16:49:36 2008 +0000
@@ -410,7 +410,7 @@
 		# If the char was training before and now has stopped then cancel
 		# the announcement
 		del_one_shot_timer($f->{timer}) if defined $f->{timer};
-		next;
+		return;
 	}
 
 	# Check for changes in the skill, skip or cancel announcement
@@ -419,9 +419,20 @@
 		del_one_shot_timer($f->{timer});
 	}
 
+	my $finish = $skill->finish_time - time();
+	my $prefinish = $finish - 60;
+
 	irc_debug("Character %s is training %s %lu (%s == %lu sec)",
 			  $f->{char}->name, $skill->name, $skill->level,
-			  $skill->time_remaining, ($skill->finish_time - time()));
+			  $skill->time_remaining, $finish);
+
+	# Cap time at 3 months to ignore bad data
+	if ($finish > 60 * 60 * 24 * 90)
+	{
+		irc_debug("Unreasonable finish time given of %s seconds, ignoring",
+				  $finish);
+		return;
+	}
 
 	$f->{skill} = $skill;
 
@@ -432,9 +443,6 @@
 		$text =~ s/[\n\r]/ /g;
 	}
 
-	my $finish = $skill->finish_time - time();
-	my $prefinish = $finish - 60;
-
 	# Add a timer shortly before the end to ensure the user's still training
 	if ($prefinish > 0)
 	{