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>
|
||||
public class SyncHandler {
|
||||
|
||||
public static double LastTimestamp = NetworkHelper.GetCurrentSystemTime();
|
||||
|
||||
private SyncDB SyncDB;
|
||||
private int LatestSyncID = -1;
|
||||
|
||||
@ -47,8 +49,12 @@ namespace Cyber.Networking.Clientside {
|
||||
}
|
||||
}
|
||||
|
||||
if (FailedSyncBases.Count > 0) {
|
||||
Client.Send(PktType.FailedChecksums, new IntListPkt(FailedSyncBases.ToArray()));
|
||||
}
|
||||
|
||||
LastTimestamp = SyncPacket.Timestamp;
|
||||
}
|
||||
}
|
||||
// Otherwise disregard the sync.
|
||||
|
||||
|
@ -19,11 +19,6 @@ 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>
|
||||
@ -48,7 +43,6 @@ namespace Cyber.Networking.Messages {
|
||||
public override void Deserialize(NetworkReader reader) {
|
||||
Direction = reader.ReadVector3();
|
||||
SyncBaseID = reader.ReadInt32();
|
||||
Timestamp = reader.ReadDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -58,7 +52,6 @@ namespace Cyber.Networking.Messages {
|
||||
public override void Serialize(NetworkWriter writer) {
|
||||
writer.Write(Direction);
|
||||
writer.Write(SyncBaseID);
|
||||
writer.Write(Timestamp);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,11 @@ namespace Cyber.Networking.Messages {
|
||||
/// </summary>
|
||||
public class SyncPkt : MessageBase {
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp of the sync packet when sent from the server.
|
||||
/// </summary>
|
||||
public double Timestamp;
|
||||
|
||||
/// <summary>
|
||||
/// The Sync Packet ID of this packet.
|
||||
/// </summary>
|
||||
@ -40,12 +45,13 @@ namespace Cyber.Networking.Messages {
|
||||
/// <param name="checksummedSyncBases"></param>
|
||||
/// <param name="checksums"></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;
|
||||
SyncDB = syncDB;
|
||||
SyncedSyncBases = syncBases;
|
||||
ChecksummedSyncBases = checksummedSyncBases;
|
||||
Checksums = checksums;
|
||||
timestamp = Timestamp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -200,7 +200,6 @@ namespace Cyber.Networking.Serverside {
|
||||
if (Player.Value.Connection.connectionId == msg.conn.connectionId) {
|
||||
continue;
|
||||
}
|
||||
MoveCreature.Timestamp = NetworkHelper.GetCurrentSystemTime();
|
||||
NetworkServer.SendToClient(Player.Value.Connection.connectionId, PktType.MoveCreature, MoveCreature);
|
||||
}
|
||||
break;
|
||||
|
@ -62,7 +62,8 @@ namespace Cyber.Networking.Serverside {
|
||||
|
||||
if (QueuedSyncs.Count > 0) {
|
||||
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);
|
||||
|
||||
QueuedSyncs.Clear();
|
||||
|
Loading…
Reference in New Issue
Block a user