12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Unity.Networking.Transport;
- namespace KairoEngine.Multiplayer
- {
- public class NetAcceptHandshakeMsg : NetMsg
- {
- public override uint code { get { return (uint)NetOpCode.AcceptHandshake; }}
- public string playerName = "";
- public uint tick = 0;
- public NetAcceptHandshakeMsg() {}
- public override void Serialize(ref DataStreamWriter writer)
- {
- writer.WriteByte((byte)code);
- writer.WriteFixedString64(playerName);
- writer.WriteUInt(tick);
- }
- public override void Deserialize(ref DataStreamReader reader)
- {
- playerName = reader.ReadFixedString64().ToString();
- tick = reader.ReadUInt();
- }
- public override void SendMessage(ServerBehaviour server, NetMsg netMsg, ref DataStreamWriter writer, int clientId)
- {
- if(server == null) return;
- NetAcceptHandshakeMsg netAcceptHandshakeMsg = (NetAcceptHandshakeMsg)netMsg;
- string text = $"Accepting handshake from client (ID {clientId}, playerName = {netAcceptHandshakeMsg.playerName}, tick = {netAcceptHandshakeMsg.tick})";
- if(server.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{server.eventStreamName}_AcceptingHandshake", text, clientId, code, netAcceptHandshakeMsg);
- netAcceptHandshakeMsg.Serialize(ref writer);
- }
- public override NetMsg ReceiveMessage(ClientBehaviour client, ref DataStreamReader stream)
- {
- NetAcceptHandshakeMsg netAcceptHandshakeMsg = new NetAcceptHandshakeMsg();
- netAcceptHandshakeMsg.Deserialize(ref stream);
- return netAcceptHandshakeMsg;
- }
- public override void ReadMessage(ClientBehaviour client)
- {
- string text = $"Server accepted handshake (playerName = {playerName}, tick = {tick})";
- if(client.debug) Debug.Log(text);
- NetMsgEvents.Trigger($"{client.eventStreamName}_HandshakeAccepted", text, -1, code, this);
- }
- }
- }
|