Mercurial > hg > skillbot
comparison skillbot.pl @ 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 |
comparison
equal
deleted
inserted
replaced
16:e238f28f774a | 17:bef72aa85f2b |
---|---|
408 unless (defined $skill) | 408 unless (defined $skill) |
409 { | 409 { |
410 # If the char was training before and now has stopped then cancel | 410 # If the char was training before and now has stopped then cancel |
411 # the announcement | 411 # the announcement |
412 del_one_shot_timer($f->{timer}) if defined $f->{timer}; | 412 del_one_shot_timer($f->{timer}) if defined $f->{timer}; |
413 next; | 413 return; |
414 } | 414 } |
415 | 415 |
416 # Check for changes in the skill, skip or cancel announcement | 416 # Check for changes in the skill, skip or cancel announcement |
417 if (defined $f->{skill}) { | 417 if (defined $f->{skill}) { |
418 next if $skill->id == $f->{skill}->id; | 418 next if $skill->id == $f->{skill}->id; |
419 del_one_shot_timer($f->{timer}); | 419 del_one_shot_timer($f->{timer}); |
420 } | 420 } |
421 | 421 |
422 my $finish = $skill->finish_time - time(); | |
423 my $prefinish = $finish - 60; | |
424 | |
422 irc_debug("Character %s is training %s %lu (%s == %lu sec)", | 425 irc_debug("Character %s is training %s %lu (%s == %lu sec)", |
423 $f->{char}->name, $skill->name, $skill->level, | 426 $f->{char}->name, $skill->name, $skill->level, |
424 $skill->time_remaining, ($skill->finish_time - time())); | 427 $skill->time_remaining, $finish); |
428 | |
429 # Cap time at 3 months to ignore bad data | |
430 if ($finish > 60 * 60 * 24 * 90) | |
431 { | |
432 irc_debug("Unreasonable finish time given of %s seconds, ignoring", | |
433 $finish); | |
434 return; | |
435 } | |
425 | 436 |
426 $f->{skill} = $skill; | 437 $f->{skill} = $skill; |
427 | 438 |
428 my $text = sprintf("%s has completed training skill %s %s", | 439 my $text = sprintf("%s has completed training skill %s %s", |
429 $f->{char}->name, $skill->name, $skill->level); | 440 $f->{char}->name, $skill->name, $skill->level); |
430 | 441 |
431 if ($text =~ /[\n\r]/) { | 442 if ($text =~ /[\n\r]/) { |
432 $text =~ s/[\n\r]/ /g; | 443 $text =~ s/[\n\r]/ /g; |
433 } | 444 } |
434 | |
435 my $finish = $skill->finish_time - time(); | |
436 my $prefinish = $finish - 60; | |
437 | 445 |
438 # Add a timer shortly before the end to ensure the user's still training | 446 # Add a timer shortly before the end to ensure the user's still training |
439 if ($prefinish > 0) | 447 if ($prefinish > 0) |
440 { | 448 { |
441 add_one_shot_timer($prefinish, sub { | 449 add_one_shot_timer($prefinish, sub { |