ServUO Version
Publish 58
Ultima Expansion
None
Could an admin double-check this method?
C#:
public override void WriteDeltaTime(DateTime value)
{
            var ticks = value.Ticks;
            var now = DateTime.UtcNow.Ticks;
            TimeSpan d;
            try
            {
                d = new TimeSpan(ticks - now);
            }

            catch (Exception ex)
            {
                if (ticks < now)
                {
                    d = TimeSpan.MaxValue;
                }
                else
                {
                    d = TimeSpan.MaxValue;
                }

                Diagnostics.ExceptionLogging.LogException(ex);

            }

          Write(d);
}

if (ticks < now) is assigns the same value,
wondering if the latter is supposed to be d = TimeSpan.MinValue;
or something else?
 
not sure I'm following this completely but it seems like you are trying to make sure the timespan is a positive value? If so, I would suggest a check for which is greater before subtracting the now from ticks or visa versa, ie if (ticks > now) { d = new TimeSpan(ticks - now); } else { d = new TimeSpan(now - ticks); }
 
I am not quite sure what you exactly want? Do you want to have negative values? Do you just want the absolute value of the delta?

If its the absolute?
 
Just saying:

C#:
if (ticks < now)
{
    d = TimeSpan.MaxValue;
}
else
{
    d = TimeSpan.MaxValue;
}
this is assigning the same value, not sure if it's supposed to be TimeSpan.MaxValue : TimeSpan.MinValue.

C#:
        public override DateTime ReadDeltaTime()
        {
            var ticks = m_File.ReadInt64();
            var now = DateTime.UtcNow.Ticks;

            if (ticks > 0 && (ticks + now) < 0)
            {
                return DateTime.MaxValue;
            }
            else if (ticks < 0 && (ticks + now) < 0)
            {
                return DateTime.MinValue;
            }

            try
            {
                return new DateTime(now + ticks);
            }
            catch (Exception e)
            {
                Diagnostics.ExceptionLogging.LogException(e);

                if (ticks > 0)
                {
                    return DateTime.MaxValue;
                }
                else
                {
                    return DateTime.MinValue;
                }
            }
        }

        public override void WriteDeltaTime(DateTime value)
        {
            var ticks = value.Ticks;
            var now = DateTime.UtcNow.Ticks;

            TimeSpan d;

            try
            {
                d = new TimeSpan(ticks - now);
            }
            catch (Exception ex)
            {
                if (ticks < now)
                {
                    d = TimeSpan.MaxValue;
                }
                else
                {
                    d = TimeSpan.MaxValue;
                }

                Diagnostics.ExceptionLogging.LogException(ex);
            }

            Write(d);
        }
Note: the ReadDeltaTime assigns different values than the WriteDeltaTime
 
Last edited:
Back