|
@@ -1,4 +1,5 @@
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
|
+using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
using Unity.Networking.Transport;
|
|
using Unity.Networking.Transport;
|
|
@@ -8,6 +9,55 @@ namespace KairoEngine.Multiplayer
|
|
{
|
|
{
|
|
public static class NetMsgController
|
|
public static class NetMsgController
|
|
{
|
|
{
|
|
|
|
+ private static List<NetMsg> netMessageTypes = new List<NetMsg>();
|
|
|
|
+
|
|
|
|
+ public static void GetNetMessageTypes()
|
|
|
|
+ {
|
|
|
|
+ netMessageTypes = ReflectiveEnumerator.GetEnumerableOfType<NetMsg>()
|
|
|
|
+ .Where(x => x.code != 0)
|
|
|
|
+ .Select(x => { return x; })
|
|
|
|
+ .ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static NetMsg FindWithCode(uint code)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < netMessageTypes.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if(netMessageTypes[i].code == code) return netMessageTypes[i];
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void ReceiveData(ref DataStreamReader stream, ServerBehaviour server, int clientId)
|
|
|
|
+ {
|
|
|
|
+ uint code = stream.ReadByte();
|
|
|
|
+ NetMsg msg = FindWithCode(code).ReceiveMessage(server, ref stream, clientId);
|
|
|
|
+ msg.ReadMessage(server, clientId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void ReceiveData(ref DataStreamReader stream, ClientBehaviour client)
|
|
|
|
+ {
|
|
|
|
+ uint code = stream.ReadByte();
|
|
|
|
+ NetMsg msg = FindWithCode(code).ReceiveMessage(client, ref stream);
|
|
|
|
+ msg.ReadMessage(client);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void SendData(uint code, NetMsg netMsg, ref DataStreamWriter writer, ServerBehaviour server, int clientId)
|
|
|
|
+ {
|
|
|
|
+ FindWithCode(code).SendMessage(server, netMsg, ref writer, clientId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void SendData(uint code, NetMsg netMsg, ref DataStreamWriter writer, ClientBehaviour client)
|
|
|
|
+ {
|
|
|
|
+ FindWithCode(code).SendMessage(client, netMsg, ref writer);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Remove rest of the code below
|
|
|
|
+ /*
|
|
|
|
+
|
|
public static void Deserialize(uint code, ref DataStreamReader stream, ServerBehaviour server, int clientId = -1)
|
|
public static void Deserialize(uint code, ref DataStreamReader stream, ServerBehaviour server, int clientId = -1)
|
|
=> Deserialize(code, ref stream, server, null, clientId);
|
|
=> Deserialize(code, ref stream, server, null, clientId);
|
|
|
|
|
|
@@ -43,6 +93,7 @@ namespace KairoEngine.Multiplayer
|
|
string text = $"Server accepted handshake (playerName = {netHandshakeMsg.playerName})";
|
|
string text = $"Server accepted handshake (playerName = {netHandshakeMsg.playerName})";
|
|
if(client.debug) Debug.Log(text);
|
|
if(client.debug) Debug.Log(text);
|
|
NetMsgEvents.Trigger($"{client.eventStreamName}_HandshakeAccepted", text, -1, code, netHandshakeMsg);
|
|
NetMsgEvents.Trigger($"{client.eventStreamName}_HandshakeAccepted", text, -1, code, netHandshakeMsg);
|
|
|
|
+
|
|
}
|
|
}
|
|
if(server != null)
|
|
if(server != null)
|
|
{
|
|
{
|
|
@@ -154,6 +205,8 @@ namespace KairoEngine.Multiplayer
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|