NetMsg.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Unity.Networking.Transport;
  6. namespace KairoEngine.Multiplayer
  7. {
  8. public class NetMsg : IComparable<NetMsg>
  9. {
  10. public virtual uint code { get { return (uint)NetOpCode.Generic; }}
  11. public virtual void Serialize(ref DataStreamWriter writer)
  12. {
  13. writer.WriteByte((byte)0);
  14. }
  15. public virtual void Deserialize(ref DataStreamReader reader)
  16. {
  17. }
  18. /// <summary>Send a net message from the server to a client.</summary>
  19. /// <param name="server">The server sending the message</param>
  20. /// <param name="netMsg">The actual message to be sent</param>
  21. /// <param name="writer">The driver writer object</param>
  22. /// <param name="clientId">The server connection id for the recipient of this message</param>
  23. public virtual void SendMessage(ServerBehaviour server, NetMsg netMsg, ref DataStreamWriter writer, int clientId) {}
  24. /// <summary>Send a net message from a client to the server.</summary>
  25. /// <param name="client">The client sending the message</param>
  26. /// <param name="netMsg">The actual message to be sent</param>
  27. /// <param name="writer">The driver writer object</param>
  28. public virtual void SendMessage(ClientBehaviour client, NetMsg netMsg, ref DataStreamWriter writer) {}
  29. public virtual NetMsg ReceiveMessage(ServerBehaviour server, ref DataStreamReader stream, int clientId = -1) => null;
  30. public virtual NetMsg ReceiveMessage(ClientBehaviour client, ref DataStreamReader stream) => null;
  31. public virtual void ReadMessage(ServerBehaviour server, int clientId = -1) {}
  32. public virtual void ReadMessage(ClientBehaviour client) {}
  33. public int CompareTo(NetMsg other)
  34. {
  35. throw new NotImplementedException();
  36. }
  37. }
  38. }