Add timestamp to sync packets and clean up client synchandling
This commit is contained in:
parent
e1cf43c8c1
commit
7feff52f69
@ -14,6 +14,8 @@ namespace Cyber.Networking.Clientside {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SyncHandler {
|
public class SyncHandler {
|
||||||
|
|
||||||
|
public static double LastTimestamp = NetworkHelper.GetCurrentSystemTime();
|
||||||
|
|
||||||
private SyncDB SyncDB;
|
private SyncDB SyncDB;
|
||||||
private int LatestSyncID = -1;
|
private int LatestSyncID = -1;
|
||||||
|
|
||||||
@ -47,8 +49,12 @@ namespace Cyber.Networking.Clientside {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FailedSyncBases.Count > 0) {
|
||||||
Client.Send(PktType.FailedChecksums, new IntListPkt(FailedSyncBases.ToArray()));
|
Client.Send(PktType.FailedChecksums, new IntListPkt(FailedSyncBases.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LastTimestamp = SyncPacket.Timestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Otherwise disregard the sync.
|
// Otherwise disregard the sync.
|
||||||
|
|
||||||
|
@ -19,11 +19,6 @@ 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>
|
||||||
@ -48,7 +43,6 @@ 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>
|
||||||
@ -58,7 +52,6 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,11 @@ namespace Cyber.Networking.Messages {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SyncPkt : MessageBase {
|
public class SyncPkt : MessageBase {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Timestamp of the sync packet when sent from the server.
|
||||||
|
/// </summary>
|
||||||
|
public double Timestamp;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Sync Packet ID of this packet.
|
/// The Sync Packet ID of this packet.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,12 +45,13 @@ namespace Cyber.Networking.Messages {
|
|||||||
/// <param name="checksummedSyncBases"></param>
|
/// <param name="checksummedSyncBases"></param>
|
||||||
/// <param name="checksums"></param>
|
/// <param name="checksums"></param>
|
||||||
/// <param name="syncPacketID">ID of the sync packet itself.</param>
|
/// <param name="syncPacketID">ID of the sync packet itself.</param>
|
||||||
public SyncPkt(SyncDB syncDB, int[] syncBases, int[] checksummedSyncBases, int[] checksums, int syncPacketID) {
|
public SyncPkt(SyncDB syncDB, int[] syncBases, int[] checksummedSyncBases, int[] checksums, int syncPacketID, double timestamp) {
|
||||||
SyncPacketID = syncPacketID;
|
SyncPacketID = syncPacketID;
|
||||||
SyncDB = syncDB;
|
SyncDB = syncDB;
|
||||||
SyncedSyncBases = syncBases;
|
SyncedSyncBases = syncBases;
|
||||||
ChecksummedSyncBases = checksummedSyncBases;
|
ChecksummedSyncBases = checksummedSyncBases;
|
||||||
Checksums = checksums;
|
Checksums = checksums;
|
||||||
|
timestamp = Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -200,7 +200,6 @@ namespace Cyber.Networking.Serverside {
|
|||||||
if (Player.Value.Connection.connectionId == msg.conn.connectionId) {
|
if (Player.Value.Connection.connectionId == msg.conn.connectionId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MoveCreature.Timestamp = NetworkHelper.GetCurrentSystemTime();
|
|
||||||
NetworkServer.SendToClient(Player.Value.Connection.connectionId, PktType.MoveCreature, MoveCreature);
|
NetworkServer.SendToClient(Player.Value.Connection.connectionId, PktType.MoveCreature, MoveCreature);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -62,7 +62,8 @@ namespace Cyber.Networking.Serverside {
|
|||||||
|
|
||||||
if (QueuedSyncs.Count > 0) {
|
if (QueuedSyncs.Count > 0) {
|
||||||
int[] SyncIDs = QueuedSyncs.ToArray();
|
int[] SyncIDs = QueuedSyncs.ToArray();
|
||||||
SyncPkt SyncPacket = new SyncPkt(Database, SyncIDs, checksummedIds.ToArray(), checksums.ToArray(), NextSyncID());
|
SyncPkt SyncPacket = new SyncPkt(Database, SyncIDs, checksummedIds.ToArray(),
|
||||||
|
checksums.ToArray(), NextSyncID(), NetworkHelper.GetCurrentSystemTime());
|
||||||
Server.SendToAllByChannel(PktType.Sync, SyncPacket, NetworkChannelID.Unreliable);
|
Server.SendToAllByChannel(PktType.Sync, SyncPacket, NetworkChannelID.Unreliable);
|
||||||
|
|
||||||
QueuedSyncs.Clear();
|
QueuedSyncs.Clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user