Hopefully fix ping this time
This commit is contained in:
parent
bb6cbb4c4d
commit
ffae0d05a8
@ -23,6 +23,8 @@ namespace Cyber.Networking.Clientside {
|
||||
private int LastSyncID = -1;
|
||||
private int SyncPacketsTotal = -1;
|
||||
|
||||
private double LastPing = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the SyncHandler with SyncDB.
|
||||
/// </summary>
|
||||
@ -60,6 +62,8 @@ namespace Cyber.Networking.Clientside {
|
||||
|
||||
LastTimestamp = SyncPacket.Timestamp;
|
||||
|
||||
LastPing = NetworkHelper.GetTime() - LastTimestamp;
|
||||
|
||||
LastSyncID = SyncPacket.SyncPacketID;
|
||||
if (SmallestSyncID == -1) {
|
||||
SmallestSyncID = SyncPacket.SyncPacketID;
|
||||
@ -70,8 +74,8 @@ namespace Cyber.Networking.Clientside {
|
||||
|
||||
}
|
||||
|
||||
public float GetPing() {
|
||||
return (float) ((NetworkHelper.GetTime() - LastTimestamp) * 1000f);
|
||||
public double GetPing() {
|
||||
return LastPing * 1000.0;
|
||||
}
|
||||
|
||||
public float GetPacketLoss() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using Cyber.Console;
|
||||
using Cyber.Entities;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
@ -12,7 +13,7 @@ namespace Cyber.Networking.Messages {
|
||||
/// <summary>
|
||||
/// Timestamp of the sync packet when sent from the server.
|
||||
/// </summary>
|
||||
public float Timestamp;
|
||||
public double Timestamp;
|
||||
|
||||
/// <summary>
|
||||
/// The Sync Packet ID of this packet.
|
||||
@ -44,7 +45,7 @@ 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, float timestamp) {
|
||||
public SyncPkt(SyncDB syncDB, int[] syncBases, int[] checksummedSyncBases, int[] checksums, int syncPacketID, double timestamp) {
|
||||
SyncPacketID = syncPacketID;
|
||||
SyncDB = syncDB;
|
||||
SyncedSyncBases = syncBases;
|
||||
@ -70,7 +71,7 @@ namespace Cyber.Networking.Messages {
|
||||
public override void Deserialize(NetworkReader reader) {
|
||||
SyncPacketID = reader.ReadInt32();
|
||||
|
||||
Timestamp = (float) reader.ReadDouble();
|
||||
Timestamp = reader.ReadDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -56,7 +56,9 @@ namespace Cyber.Networking {
|
||||
/// </summary>
|
||||
/// <returns>The system time in seconds.</returns>
|
||||
public static double GetTime() {
|
||||
return Network.time;
|
||||
return DateTime.Now.ToUniversalTime().Subtract(
|
||||
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
|
||||
.TotalMilliseconds * 1.0 / 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using Cyber.Console;
|
||||
using Cyber.Entities;
|
||||
using Cyber.Networking.Messages;
|
||||
using System;
|
||||
@ -63,7 +64,7 @@ namespace Cyber.Networking.Serverside {
|
||||
if (QueuedSyncs.Count > 0) {
|
||||
int[] SyncIDs = QueuedSyncs.ToArray();
|
||||
SyncPkt SyncPacket = new SyncPkt(Database, SyncIDs, checksummedIds.ToArray(),
|
||||
checksums.ToArray(), NextSyncID(), (float) NetworkHelper.GetTime());
|
||||
checksums.ToArray(), NextSyncID(), NetworkHelper.GetTime());
|
||||
Server.SendToAllByChannel(PktType.Sync, SyncPacket, NetworkChannelID.Unreliable);
|
||||
|
||||
QueuedSyncs.Clear();
|
||||
|
Loading…
Reference in New Issue
Block a user