Browse Source

Added NetworkTick to Client/Server Status

James Peret 2 years ago
parent
commit
6e34608d36
3 changed files with 12 additions and 1 deletions
  1. 1 1
      Readme.md
  2. 5 0
      Runtime/Client/ClientStatus.cs
  3. 6 0
      Runtime/Server/ServerStatus.cs

+ 1 - 1
Readme.md

@@ -26,6 +26,6 @@ Server and clients exchange Net Messages which then become local events that can
 | client | SendData    | NetHandshakeMsg          | SendingHandshake                 |
 | client | ReceiveData | NetHandshakeMsg          | HandshakeAccepted                |
 | client | ReceiveData | NetClientConnectedMsg    | PeerConnected                    |
-|        | ReceiveData | NetClientDisconnectedMsg | PeerDisconnected                 |
+| client | ReceiveData | NetClientDisconnectedMsg | PeerDisconnected                 |
 
 

+ 5 - 0
Runtime/Client/ClientStatus.cs

@@ -2,6 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Sirenix.OdinInspector;
+using KairoEngine.Core;
 
 namespace KairoEngine.Multiplayer
 {
@@ -19,6 +20,7 @@ namespace KairoEngine.Multiplayer
         [ReadOnly] public ClientState state;
         [ReadOnly] public int peerCount;
         [ReadOnly] public float uptime = 0;
+        [ReadOnly] public int tick = 0;
         [ReadOnly] public string serverAddress;
         [ReadOnly] public int packetsSent;
         [ReadOnly] public int packetsReceived;
@@ -30,6 +32,7 @@ namespace KairoEngine.Multiplayer
             NetMsgEvents.StartListening($"{client.eventStreamName}_ServerDisconnect", OnReceivePacket);
             NetMsgEvents.StartListening($"{client.eventStreamName}_SendingHandshake", OnSentPacket);
             NetMsgEvents.StartListening($"{client.eventStreamName}_HandshakeAccepted", OnReceivePacket);
+            GenericEvents.StartListening($"{client.eventStreamName}_OnTick", OnTick);
         }
 
         private void OnDisable()
@@ -62,5 +65,7 @@ namespace KairoEngine.Multiplayer
         private void OnSentPacket(string text, int clientId, uint code, NetMsg netMsg) => packetsSent += 1;
 
         private void OnReceivePacket(string text, int clientId, uint code, NetMsg netMsg) => packetsReceived += 1;
+
+        private void OnTick(int newTick) => tick = newTick;
     }
 }

+ 6 - 0
Runtime/Server/ServerStatus.cs

@@ -1,6 +1,7 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using KairoEngine.Core;
 using Sirenix.OdinInspector;
 
 namespace KairoEngine.Multiplayer
@@ -19,6 +20,7 @@ namespace KairoEngine.Multiplayer
         [ReadOnly] public int clientCount;
         [ReadOnly] public int maxClients;
         [ReadOnly] public float uptime = 0;
+        [ReadOnly] public int tick = 0;
         [ReadOnly] public string ipAddress;
         [ReadOnly] public int packetsSent;
         [ReadOnly] public int packetsReceived;
@@ -30,6 +32,7 @@ namespace KairoEngine.Multiplayer
             NetMsgEvents.StartListening($"{server.eventStreamName}_ClientDisconnect", OnReceivePacket);
             NetMsgEvents.StartListening($"{server.eventStreamName}_HandshakeReceived", OnReceivePacket);
             NetMsgEvents.StartListening($"{server.eventStreamName}_AcceptingHandshake", OnSentPacket);
+            GenericEvents.StartListening($"{server.eventStreamName}_OnTick", OnTick);
         }
 
         private void OnDisable()
@@ -39,6 +42,7 @@ namespace KairoEngine.Multiplayer
             NetMsgEvents.StopListening($"{server.eventStreamName}_ClientDisconnect", OnReceivePacket);
             NetMsgEvents.StopListening($"{server.eventStreamName}_HandshakeReceived", OnReceivePacket);
             NetMsgEvents.StopListening($"{server.eventStreamName}_AcceptingHandshake", OnSentPacket);
+            GenericEvents.StopListening($"{server.eventStreamName}_OnTick", OnTick);
         }
 
         private void Update()
@@ -67,5 +71,7 @@ namespace KairoEngine.Multiplayer
         private void OnSentPacket(string text, int clientId, uint code, NetMsg netMsg) => packetsSent += 1;
 
         private void OnReceivePacket(string text, int clientId, uint code, NetMsg netMsg) => packetsReceived += 1;
+
+        private void OnTick(int newTick) => tick = newTick;
     }
 }