Added logging

This commit is contained in:
MrGadget 2024-05-20 07:33:00 -04:00
parent c573936486
commit a3c52f7785
3 changed files with 46 additions and 3 deletions

View File

@ -125,6 +125,15 @@ protected virtual void UpdatePing()
// localTime (double) instead of Time.time for accuracy over days
if (NetworkTime.localTime >= lastPingTime + NetworkTime.PingInterval)
{
Debug.Log($"{DateTime.Now:HH:mm:ss:fff} UpdatePing {this}");
if (Utils.IsHeadless())
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"{DateTime.Now:HH:mm:ss:fff} UpdatePing {this}");
Console.ResetColor();
}
// TODO it would be safer for the server to store the last N
// messages' timestamp and only send a message number.
// This way client's can't just modify the timestamp.

View File

@ -1360,7 +1360,17 @@ void OnClientSceneInternal(SceneMessage msg)
}
/// <summary>Called on the server when a new client connects.</summary>
public virtual void OnServerConnect(NetworkConnectionToClient conn) { }
public virtual void OnServerConnect(NetworkConnectionToClient conn)
{
Debug.Log($"{DateTime.Now:HH:mm:ss:fff} NetworkManager.OnServerConnectInternal {conn}");
if (Utils.IsHeadless())
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"{DateTime.Now:HH:mm:ss:fff} NetworkManager.OnServerConnectInternal {conn}");
Console.ResetColor();
}
}
/// <summary>Called on the server when a client disconnects.</summary>
// Called by NetworkServer.OnTransportDisconnect!
@ -1492,7 +1502,10 @@ public virtual void OnStartHost() { }
public virtual void OnStartServer() { }
/// <summary>This is invoked when the client is started.</summary>
public virtual void OnStartClient() { }
public virtual void OnStartClient()
{
Debug.Log("OnStartClient");
}
/// <summary>This is called when a server is stopped - including when a host is stopped.</summary>
public virtual void OnStopServer() { }

View File

@ -147,6 +147,8 @@ internal static void UpdateClient()
// Separate method so we can call it from NetworkClient directly.
internal static void SendPing()
{
Debug.Log($"SendPing");
// send raw predicted time without the offset applied yet.
// we then apply the offset to it after.
NetworkPingMessage pingMessage = new NetworkPingMessage
@ -164,6 +166,15 @@ internal static void SendPing()
// and time from the server
internal static void OnServerPing(NetworkConnectionToClient conn, NetworkPingMessage message)
{
Debug.Log($"{DateTime.Now:HH:mm:ss:fff} OnServerPing {conn}");
if (Utils.IsHeadless())
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"{DateTime.Now:HH:mm:ss:fff} OnServerPing {conn}");
Console.ResetColor();
}
// calculate the prediction offset that the client needs to apply to unadjusted time to reach server time.
// this will be sent back to client for corrections.
double unadjustedError = localTime - message.localTime;
@ -191,6 +202,7 @@ internal static void OnServerPing(NetworkConnectionToClient conn, NetworkPingMes
// and update time offset & prediction offset.
internal static void OnClientPong(NetworkPongMessage message)
{
Debug.Log("OnClientPong");
// prevent attackers from sending timestamps which are in the future
if (message.localTime > localTime) return;
@ -211,7 +223,7 @@ internal static void OnClientPong(NetworkPongMessage message)
// reply with a pong containing the time from the server
internal static void OnClientPing(NetworkPingMessage message)
{
// Debug.Log($"OnClientPing conn:{conn}");
Debug.Log("OnClientPing");
NetworkPongMessage pongMessage = new NetworkPongMessage
(
message.localTime,
@ -225,6 +237,15 @@ internal static void OnClientPing(NetworkPingMessage message)
// and update time offset
internal static void OnServerPong(NetworkConnectionToClient conn, NetworkPongMessage message)
{
Debug.Log($"{DateTime.Now:HH:mm:ss:fff} OnServerPong {conn}");
if (Utils.IsHeadless())
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"{DateTime.Now:HH:mm:ss:fff} OnServerPong {conn}");
Console.ResetColor();
}
// prevent attackers from sending timestamps which are in the future
if (message.localTime > localTime) return;