- my $lastid = $parent->lastid || 0;
- if ($t < $lastid) {
- if ($t+86400-$lastid > $pc9x_past_age) {
- dbg("PCPROT: dup id on $t <= $lastid, ignored") if isdbg('chanerr');
- return;
- }
- } elsif ($t == $lastid) {
- dbg("PCPROT: dup id on $t == $lastid, ignored") if isdbg('chanerr');
- return;
- } else {
- # $t > $lastid, check that the timestamp offered isn't too far away from 'now'
- if ($t+$main::systime_daystart-$main::systime > $pc9x_future_age ) {
- dbg("PCPROT: id $t too far in the future, ignored") if isdbg('chanerr');
- return;
+ my $lastid = $parent->lastid;
+ if (defined $lastid) {
+ if ($t < $lastid) {
+ # note that this is where we determine whether this pc9x has come in yesterday
+ # but is still greater (modulo 86400) than the lastid or is simply an old
+ # duplicate sentence. To determine this we need to do some module 86400
+ # arithmetic. High numbers mean that this is an old duplicate sentence,
+ # low numbers that it is a new sentence.
+ #
+ # Typically you will see yesterday being taken on $t = 84, $lastid = 86235
+ # and old dupes with $t = 234, $lastid = 256 (which give answers 249 and
+ # 86378 respectively in the calculation below).
+ #
+ if ($t+86400-$lastid > $pc9x_past_age) {
+ dbg("PCPROT: dup id on $t <= lastid $lastid, ignored") if isdbg('chanerr') || isdbg('pc92dedupe');
+ return undef;
+ }
+ } elsif ($t == $lastid) {
+ dbg("PCPROT: dup id on $t == lastid $lastid, ignored") if isdbg('chanerr') || isdbg('pc92dedupe');
+ return undef;
+ } else {
+ # check that if we have a low number in lastid that yesterday's numbers
+ # (likely in the 85000+ area) don't override them, thus causing flip flopping
+ if ($lastid+86400-$t < $pc9x_past_age) {
+ dbg("PCPROT: dup id on $t in yesterday, lastid $lastid, ignored") if isdbg('chanerr') || isdbg('pc92dedupe');
+ return undef;
+ }