Add timestamps to movement packets

This commit is contained in:
Sofia 2017-05-09 08:15:24 +03:00
parent 897e797195
commit 2239e336f5
3 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,11 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
public int SyncBaseID; public int SyncBaseID;
/// <summary>
/// Time when server received this request. Used for compensating ping.
/// </summary>
public double Timestamp;
/// <summary> /// <summary>
/// Creates a MoveCreaturePkt which contains the direction of desired movement (or (0, 0, 0) for stopping) /// Creates a MoveCreaturePkt which contains the direction of desired movement (or (0, 0, 0) for stopping)
/// </summary> /// </summary>
@ -43,6 +48,7 @@ namespace Cyber.Networking.Messages {
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
Direction = reader.ReadVector3(); Direction = reader.ReadVector3();
SyncBaseID = reader.ReadInt32(); SyncBaseID = reader.ReadInt32();
Timestamp = reader.ReadDouble();
} }
/// <summary> /// <summary>
@ -52,6 +58,7 @@ namespace Cyber.Networking.Messages {
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
writer.Write(Direction); writer.Write(Direction);
writer.Write(SyncBaseID); writer.Write(SyncBaseID);
writer.Write(Timestamp);
} }
} }

View File

@ -51,5 +51,15 @@ namespace Cyber.Networking {
return IntArray; return IntArray;
} }
/// <summary>
/// Returns the current system time in seconds.
/// </summary>
/// <returns>The system time in seconds.</returns>
public static double GetCurrentSystemTime() {
return DateTime.Now.ToUniversalTime().Subtract(
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds * 1.0 / 1000;
}
} }
} }

View File

@ -141,6 +141,7 @@ namespace Cyber.Networking.Serverside {
if (Player.Value.ConnectionID == msg.conn.connectionId) { if (Player.Value.ConnectionID == msg.conn.connectionId) {
continue; continue;
} }
MoveCreature.Timestamp = NetworkHelper.GetCurrentSystemTime();
NetworkServer.SendToClient(Player.Value.ConnectionID, PktType.MoveCreature, MoveCreature); NetworkServer.SendToClient(Player.Value.ConnectionID, PktType.MoveCreature, MoveCreature);
} }
break; break;