Add timestamps to movement packets
This commit is contained in:
parent
897e797195
commit
2239e336f5
@ -19,6 +19,11 @@ namespace Cyber.Networking.Messages {
|
||||
/// </summary>
|
||||
public int SyncBaseID;
|
||||
|
||||
/// <summary>
|
||||
/// Time when server received this request. Used for compensating ping.
|
||||
/// </summary>
|
||||
public double Timestamp;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a MoveCreaturePkt which contains the direction of desired movement (or (0, 0, 0) for stopping)
|
||||
/// </summary>
|
||||
@ -43,6 +48,7 @@ namespace Cyber.Networking.Messages {
|
||||
public override void Deserialize(NetworkReader reader) {
|
||||
Direction = reader.ReadVector3();
|
||||
SyncBaseID = reader.ReadInt32();
|
||||
Timestamp = reader.ReadDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -52,6 +58,7 @@ namespace Cyber.Networking.Messages {
|
||||
public override void Serialize(NetworkWriter writer) {
|
||||
writer.Write(Direction);
|
||||
writer.Write(SyncBaseID);
|
||||
writer.Write(Timestamp);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,5 +51,15 @@ namespace Cyber.Networking {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ namespace Cyber.Networking.Serverside {
|
||||
if (Player.Value.ConnectionID == msg.conn.connectionId) {
|
||||
continue;
|
||||
}
|
||||
MoveCreature.Timestamp = NetworkHelper.GetCurrentSystemTime();
|
||||
NetworkServer.SendToClient(Player.Value.ConnectionID, PktType.MoveCreature, MoveCreature);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user