using System.Collections; using System.Collections.Generic; using UnityEngine; using Unity.Networking.Transport; namespace KairoEngine.Multiplayer { public class NetPongMsg : NetMsg { public override uint code { get { return (uint)NetOpCode.Pong; }} public uint pingId; public NetPongMsg() {} public NetPongMsg(uint pingId) { this.pingId = pingId; } public override void Serialize(ref DataStreamWriter writer) { writer.WriteByte((byte)code); writer.WriteUInt(pingId); } public override void Deserialize(ref DataStreamReader reader) { pingId = reader.ReadUInt(); } public override void SendMessage(ClientBehaviour client, NetMsg netMsg, ref DataStreamWriter writer ) { if(client == null) return; NetPongMsg netPongMsg = (NetPongMsg)netMsg; string text = $"Responding pong ({netPongMsg.pingId}))"; if(client.debug) Debug.Log(text); NetMsgEvents.Trigger($"{client.eventStreamName}_PongSent", text, -1, code, netPongMsg); netPongMsg.Serialize(ref writer); } public override NetMsg ReceiveMessage(ServerBehaviour server, ref DataStreamReader stream, int clientId = -1) { NetPongMsg netPongMsg = new NetPongMsg(); netPongMsg.Deserialize(ref stream); string text = $"Received pong from client (ID {clientId}, PingId = {netPongMsg.pingId})"; if(server.debug) Debug.Log(text); NetMsgEvents.Trigger($"{server.eventStreamName}_PongReceived", text, clientId, code, netPongMsg); return netPongMsg; } public override void ReadMessage(ServerBehaviour server, int clientId = -1) { } } }