Hopefully fix ping this time

This commit is contained in:
Sofia 2017-05-17 01:33:45 +03:00
parent bb6cbb4c4d
commit ffae0d05a8
4 changed files with 15 additions and 7 deletions

View File

@ -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() {

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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();