From f3aa0d2efac389833e8178cdffbb8ac99e44bb6d Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 29 Aug 2021 16:47:22 +0100 Subject: [PATCH] cleanup qnetworkserversimple --- QuantumUNET/QNetworkServerSimple.cs | 69 +++++++++++------------------ 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/QuantumUNET/QNetworkServerSimple.cs b/QuantumUNET/QNetworkServerSimple.cs index b72be52e..62beef3e 100644 --- a/QuantumUNET/QNetworkServerSimple.cs +++ b/QuantumUNET/QNetworkServerSimple.cs @@ -13,26 +13,18 @@ namespace QuantumUNET public class QNetworkServerSimple { public QNetworkServerSimple() => connections = new ReadOnlyCollection(m_Connections); - public int listenPort { get; set; } - public int serverHostId { get; set; } = -1; - public HostTopology hostTopology { get; private set; } - - public bool useWebSockets { get; set; } - public ReadOnlyCollection connections { get; } - public Dictionary handlers => m_MessageHandlers.GetHandlers(); - public byte[] messageBuffer { get; private set; } - public NetworkReader messageReader { get; private set; } - public Type networkConnectionClass { get; private set; } = typeof(QNetworkConnection); - public void SetNetworkConnectionClass() where T : QNetworkConnection => networkConnectionClass = typeof(T); + public void SetNetworkConnectionClass() + where T : QNetworkConnection + => networkConnectionClass = typeof(T); public virtual void Initialize() { @@ -70,9 +62,7 @@ namespace QuantumUNET { Initialize(); listenPort = serverListenPort; - serverHostId = useWebSockets - ? NetworkTransport.AddWebsocketHost(hostTopology, serverListenPort, ipAddress) - : NetworkTransport.AddHost(hostTopology, serverListenPort, ipAddress); + serverHostId = NetworkTransport.AddHost(hostTopology, serverListenPort, ipAddress); bool result; if (serverHostId == -1) { @@ -87,16 +77,15 @@ namespace QuantumUNET return result; } - public bool Listen(int serverListenPort) => Listen(serverListenPort, hostTopology); + public bool Listen(int serverListenPort) + => Listen(serverListenPort, hostTopology); public bool Listen(int serverListenPort, HostTopology topology) { hostTopology = topology; Initialize(); listenPort = serverListenPort; - serverHostId = useWebSockets - ? NetworkTransport.AddWebsocketHost(hostTopology, serverListenPort) - : NetworkTransport.AddHost(hostTopology, serverListenPort); + serverHostId = NetworkTransport.AddHost(hostTopology, serverListenPort); bool result; if (serverHostId == -1) { @@ -111,17 +100,6 @@ namespace QuantumUNET return result; } - public void ListenRelay(string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId) - { - Initialize(); - serverHostId = NetworkTransport.AddHost(hostTopology, listenPort); - Debug.Log($"Server Host Slot Id: {serverHostId}"); - Update(); - NetworkTransport.ConnectAsNetworkHost(serverHostId, relayIp, relayPort, netGuid, sourceId, nodeId, out var b); - m_RelaySlotId = 0; - Debug.Log($"Relay Slot Id: {m_RelaySlotId}"); - } - public void Stop() { Debug.Log("NetworkServerSimple stop "); @@ -129,13 +107,17 @@ namespace QuantumUNET serverHostId = -1; } - internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler); + internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) + => m_MessageHandlers.RegisterHandlerSafe(msgType, handler); - public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler); + public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) + => m_MessageHandlers.RegisterHandler(msgType, handler); - public void UnregisterHandler(short msgType) => m_MessageHandlers.UnregisterHandler(msgType); + public void UnregisterHandler(short msgType) + => m_MessageHandlers.UnregisterHandler(msgType); - public void ClearHandlers() => m_MessageHandlers.ClearMessageHandlers(); + public void ClearHandlers() + => m_MessageHandlers.ClearMessageHandlers(); public void UpdateConnections() { @@ -360,20 +342,23 @@ namespace QuantumUNET } } - public virtual void OnConnectError(int connectionId, byte error) => Debug.LogError( - $"OnConnectError error:{error}"); + public virtual void OnConnectError(int connectionId, byte error) + => Debug.LogError($"OnConnectError error:{error}"); - public virtual void OnDataError(QNetworkConnection conn, byte error) => Debug.LogError( - $"OnDataError error:{error}"); + public virtual void OnDataError(QNetworkConnection conn, byte error) + => Debug.LogError($"OnDataError error:{error}"); - public virtual void OnDisconnectError(QNetworkConnection conn, byte error) => Debug.LogError( - $"OnDisconnectError error:{error}"); + public virtual void OnDisconnectError(QNetworkConnection conn, byte error) + => Debug.LogError($"OnDisconnectError error:{error}"); - public virtual void OnConnected(QNetworkConnection conn) => conn.InvokeHandlerNoData(32); + public virtual void OnConnected(QNetworkConnection conn) + => conn.InvokeHandlerNoData(32); - public virtual void OnDisconnected(QNetworkConnection conn) => conn.InvokeHandlerNoData(33); + public virtual void OnDisconnected(QNetworkConnection conn) + => conn.InvokeHandlerNoData(33); - public virtual void OnData(QNetworkConnection conn, int receivedSize, int channelId) => conn.TransportReceive(messageBuffer, receivedSize, channelId); + public virtual void OnData(QNetworkConnection conn, int receivedSize, int channelId) + => conn.TransportReceive(messageBuffer, receivedSize, channelId); private bool m_Initialized; private int m_RelaySlotId = -1;