try to avoid negative roll-over when moving to or from server time

This commit is contained in:
Seth Alves 2015-10-27 10:27:32 -07:00
parent 7d9b566d0a
commit 4c64da9ce5

View file

@ -247,15 +247,29 @@ bool ObjectAction::lifetimeIsOver() {
}
quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) const {
// 0 indicates no expiration
if (timeValue == 0) {
return 0;
}
return timeValue + getEntityServerClockSkew();
int serverClockSkew = getEntityServerClockSkew();
if (serverClockSkew < 0 && timeValue <= (quint64)(-serverClockSkew)) {
return 1; // non-zero but long-expired value to avoid negative roll-over
}
return timeValue + serverClockSkew;
}
quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) const {
// 0 indicates no expiration
if (timeValue == 0) {
return 0;
}
return timeValue - getEntityServerClockSkew();
int serverClockSkew = getEntityServerClockSkew();
if (serverClockSkew > 0 && timeValue <= (quint64)serverClockSkew) {
return 1; // non-zero but long-expired value to avoid negative roll-over
}
return timeValue - serverClockSkew;
}