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 LastSyncID = -1;
|
||||||
private int SyncPacketsTotal = -1;
|
private int SyncPacketsTotal = -1;
|
||||||
|
|
||||||
|
private double LastPing = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the SyncHandler with SyncDB.
|
/// Creates the SyncHandler with SyncDB.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -60,6 +62,8 @@ namespace Cyber.Networking.Clientside {
|
|||||||
|
|
||||||
LastTimestamp = SyncPacket.Timestamp;
|
LastTimestamp = SyncPacket.Timestamp;
|
||||||
|
|
||||||
|
LastPing = NetworkHelper.GetTime() - LastTimestamp;
|
||||||
|
|
||||||
LastSyncID = SyncPacket.SyncPacketID;
|
LastSyncID = SyncPacket.SyncPacketID;
|
||||||
if (SmallestSyncID == -1) {
|
if (SmallestSyncID == -1) {
|
||||||
SmallestSyncID = SyncPacket.SyncPacketID;
|
SmallestSyncID = SyncPacket.SyncPacketID;
|
||||||
@ -70,8 +74,8 @@ namespace Cyber.Networking.Clientside {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetPing() {
|
public double GetPing() {
|
||||||
return (float) ((NetworkHelper.GetTime() - LastTimestamp) * 1000f);
|
return LastPing * 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetPacketLoss() {
|
public float GetPacketLoss() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using Cyber.Console;
|
||||||
using Cyber.Entities;
|
using Cyber.Entities;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ namespace Cyber.Networking.Messages {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timestamp of the sync packet when sent from the server.
|
/// Timestamp of the sync packet when sent from the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Timestamp;
|
public double Timestamp;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Sync Packet ID of this packet.
|
/// The Sync Packet ID of this packet.
|
||||||
@ -44,7 +45,7 @@ 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, float timestamp) {
|
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;
|
||||||
@ -70,7 +71,7 @@ namespace Cyber.Networking.Messages {
|
|||||||
public override void Deserialize(NetworkReader reader) {
|
public override void Deserialize(NetworkReader reader) {
|
||||||
SyncPacketID = reader.ReadInt32();
|
SyncPacketID = reader.ReadInt32();
|
||||||
|
|
||||||
Timestamp = (float) reader.ReadDouble();
|
Timestamp = reader.ReadDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -56,7 +56,9 @@ namespace Cyber.Networking {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The system time in seconds.</returns>
|
/// <returns>The system time in seconds.</returns>
|
||||||
public static double GetTime() {
|
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.Entities;
|
||||||
using Cyber.Networking.Messages;
|
using Cyber.Networking.Messages;
|
||||||
using System;
|
using System;
|
||||||
@ -63,7 +64,7 @@ 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(),
|
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);
|
Server.SendToAllByChannel(PktType.Sync, SyncPacket, NetworkChannelID.Unreliable);
|
||||||
|
|
||||||
QueuedSyncs.Clear();
|
QueuedSyncs.Clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user