diff --git a/Lidgren.Network/NetBuffer.Read.cs b/Lidgren.Network/NetBuffer.Read.cs
index 6b766a3..019141c 100644
--- a/Lidgren.Network/NetBuffer.Read.cs
+++ b/Lidgren.Network/NetBuffer.Read.cs
@@ -601,6 +601,20 @@ namespace Lidgren.Network
return true;
}
+ ///
+ /// Reads a value, in local time comparable to NetTime.Now, written using WriteTime() for the connection supplied
+ ///
+ public double ReadTime(NetConnection connection, bool highPrecision)
+ {
+ double remoteTime = (highPrecision ? ReadDouble() : (double)ReadSingle());
+
+ if (connection == null)
+ throw new NetException("Cannot call ReadTime() on message without a connected sender (ie. unconnected messages)");
+
+ // lets bypass NetConnection.GetLocalTime for speed
+ return remoteTime - connection.m_remoteTimeOffset;
+ }
+
///
/// Reads a stored IPv4 endpoint description
///
diff --git a/Lidgren.Network/NetBuffer.Write.cs b/Lidgren.Network/NetBuffer.Write.cs
index 2052483..f591b20 100644
--- a/Lidgren.Network/NetBuffer.Write.cs
+++ b/Lidgren.Network/NetBuffer.Write.cs
@@ -547,7 +547,19 @@ namespace Lidgren.Network
}
///
- /// Writes the local time to a message; readable (and convertable to local time) by the remote host using ReadTime()
+ /// Writes the current local time to a message; readable (and convertable to local time) by the remote host using ReadTime()
+ ///
+ public void WriteTime(bool highPrecision)
+ {
+ double localTime = NetTime.Now;
+ if (highPrecision)
+ Write(localTime);
+ else
+ Write((float)localTime);
+ }
+
+ ///
+ /// Writes a local timestamp to a message; readable (and convertable to local time) by the remote host using ReadTime()
///
public void WriteTime(double localTime, bool highPrecision)
{
diff --git a/Lidgren.Network/NetBuffer.cs b/Lidgren.Network/NetBuffer.cs
index da23d90..e530b0d 100644
--- a/Lidgren.Network/NetBuffer.cs
+++ b/Lidgren.Network/NetBuffer.cs
@@ -6,7 +6,6 @@ namespace Lidgren.Network
{
public partial class NetBuffer
{
- // @TODO Add ReadTime() to incomingmessage class
private const int c_overAllocateAmount = 4;
private static readonly Dictionary s_readMethods;
diff --git a/Lidgren.Network/NetIncomingMessage.cs b/Lidgren.Network/NetIncomingMessage.cs
index b32ac21..168d60c 100644
--- a/Lidgren.Network/NetIncomingMessage.cs
+++ b/Lidgren.Network/NetIncomingMessage.cs
@@ -95,6 +95,15 @@ namespace Lidgren.Network
return encryption.Decrypt(this);
}
+ ///
+ /// Reads a value, in local time comparable to NetTime.Now, written using WriteTime()
+ /// Must have a connected sender
+ ///
+ public double ReadTime(bool highPrecision)
+ {
+ return ReadTime(m_senderConnection, highPrecision);
+ }
+
///
/// Returns a string that represents this object
///