123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Unity.Networking.Transport;
- namespace KairoEngine.Multiplayer
- {
- public class NetDisconnectMsg : NetMsg
- {
- public override uint code { get { return (uint)NetOpCode.Disconnect; }}
- public NetDisconnectMsg() {}
- public override void Serialize(ref DataStreamWriter writer)
- {
- writer.WriteByte((byte)code);
- }
- public override void Deserialize(ref DataStreamReader reader)
- {
-
- }
- public override void SendMessage(ServerBehaviour server, NetMsg netMsg, ref DataStreamWriter writer, int clientId)
- {
- if(server == null) return;
- NetDisconnectMsg netDisconnectMsg = (NetDisconnectMsg)netMsg;
- string text = $"Sending disconnect message to client (ID {clientId})";
- if(server.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{server.eventStreamName}_SendingDisconnectMessageToClient", text, clientId, code, netDisconnectMsg);
- netDisconnectMsg.Serialize(ref writer);
- }
- public override void SendMessage(ClientBehaviour client, NetMsg netMsg, ref DataStreamWriter writer )
- {
- if(client == null) return;
- NetDisconnectMsg netDisconnectMsg = (NetDisconnectMsg)netMsg;
- string text = $"Sending disconnect message to server";
- if(client.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{client.eventStreamName}_SendingDisconnectMessageToServer", text, -1, code, netDisconnectMsg);
- netDisconnectMsg.Serialize(ref writer);
- }
- public override NetMsg ReceiveMessage(ServerBehaviour server, ref DataStreamReader stream, int clientId = -1)
- {
- NetDisconnectMsg netDisconnectMsg = new NetDisconnectMsg();
- netDisconnectMsg.Deserialize(ref stream);
- return netDisconnectMsg;
- }
- public override NetMsg ReceiveMessage(ClientBehaviour client, ref DataStreamReader stream)
- {
- NetDisconnectMsg netDisconnectMsg = new NetDisconnectMsg();
- netDisconnectMsg.Deserialize(ref stream);
- return netDisconnectMsg;
- }
- public override void ReadMessage(ServerBehaviour server, int clientId = -1)
- {
- string text = $"Client is disconnecting";
- if(server.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{server.eventStreamName}_ClientDisconnect", text, clientId, code, this);
- }
- public override void ReadMessage(ClientBehaviour client)
- {
- string text = $"Server disconnected client";
- if(client.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{client.eventStreamName}_ServerDisconnect", text, -1, code, this);
- }
- }
- }
|