From baad97070630f320c1c4e1542e4134f429e4e0a4 Mon Sep 17 00:00:00 2001 From: vis2k Date: Tue, 14 Aug 2018 22:15:34 +0200 Subject: [PATCH] Removed channels and configs everywhere --- .../Editor/NetworkBehaviourInspector.cs | 3 - .../Editor/NetworkManagerEditor.cs | 151 ------------------ .../Runtime/ClientScene.cs | 2 +- .../Runtime/CustomAttributes.cs | 5 - .../Runtime/LocalClient.cs | 11 +- .../Runtime/LocalConnections.cs | 8 +- .../Runtime/NetworkBehaviour.cs | 21 +-- .../Runtime/NetworkClient.cs | 42 +---- .../Runtime/NetworkConnection.cs | 33 ++-- .../Runtime/NetworkIdentity.cs | 36 ++--- .../Runtime/NetworkManager.cs | 102 +----------- .../Runtime/NetworkServer.cs | 70 +++----- .../Runtime/NetworkTranformChild.cs | 7 +- .../Runtime/NetworkTransform.cs | 7 +- .../Runtime/SyncList.cs | 2 +- .../Runtime/Transport.cs | 3 + .../Runtime/UNetwork.cs | 23 --- .../Weaver/UNetBehaviourProcessor.cs | 107 +------------ 18 files changed, 87 insertions(+), 546 deletions(-) diff --git a/Unity-Technologies-networking/Editor/NetworkBehaviourInspector.cs b/Unity-Technologies-networking/Editor/NetworkBehaviourInspector.cs index 0fa5bb184..e9eb09e79 100644 --- a/Unity-Technologies-networking/Editor/NetworkBehaviourInspector.cs +++ b/Unity-Technologies-networking/Editor/NetworkBehaviourInspector.cs @@ -19,7 +19,6 @@ public class NetworkBehaviourInspector : Editor bool[] m_ShowSyncLists; GUIContent m_SyncVarIndicatorContent; - protected GUIContent m_NetworkChannelLabel; protected GUIContent m_NetworkSendIntervalLabel; internal virtual bool hideScriptField @@ -33,7 +32,6 @@ void Init(MonoScript script) m_ScriptClass = script.GetClass(); m_SyncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute."); - m_NetworkChannelLabel = new GUIContent("Network Channel", "QoS channel used for updates. Use the [NetworkSettings] class attribute to change this."); m_NetworkSendIntervalLabel = new GUIContent("Network Send Interval", "Maximum update rate in seconds. Use the [NetworkSettings] class attribute to change this, or implement GetNetworkSendInterval"); foreach (var field in m_ScriptClass.GetFields(BindingFlags.Public | BindingFlags.Instance)) @@ -166,7 +164,6 @@ public override void OnInspectorGUI() var beh = target as NetworkBehaviour; if (beh != null) { - EditorGUILayout.LabelField(m_NetworkChannelLabel, new GUIContent(beh.GetNetworkChannel().ToString())); EditorGUILayout.LabelField(m_NetworkSendIntervalLabel, new GUIContent(beh.GetNetworkSendInterval().ToString())); } } diff --git a/Unity-Technologies-networking/Editor/NetworkManagerEditor.cs b/Unity-Technologies-networking/Editor/NetworkManagerEditor.cs index 04ce1840d..1cfa4f985 100644 --- a/Unity-Technologies-networking/Editor/NetworkManagerEditor.cs +++ b/Unity-Technologies-networking/Editor/NetworkManagerEditor.cs @@ -28,13 +28,8 @@ public class NetworkManagerEditor : Editor SerializedProperty m_PlayerSpawnMethodProperty; SerializedProperty m_SpawnListProperty; - SerializedProperty m_CustomConfigProperty; - SerializedProperty m_UseWebSocketsProperty; - SerializedProperty m_ChannelListProperty; - ReorderableList m_ChannelList; - GUIContent m_ShowNetworkLabel; GUIContent m_ShowSpawnLabel; @@ -43,17 +38,6 @@ public class NetworkManagerEditor : Editor protected GUIContent m_DontDestroyOnLoadLabel; protected GUIContent m_RunInBackgroundLabel; - GUIContent m_MaxConnectionsLabel; - GUIContent m_MinUpdateTimeoutLabel; - GUIContent m_ConnectTimeoutLabel; - GUIContent m_DisconnectTimeoutLabel; - GUIContent m_PingTimeoutLabel; - - GUIContent m_ThreadAwakeTimeoutLabel; - GUIContent m_ReactorModelLabel; - GUIContent m_ReactorMaximumReceivedMessagesLabel; - GUIContent m_ReactorMaximumSentMessagesLabel; - GUIContent m_UseWebSocketsLabel; GUIContent m_NetworkAddressLabel; @@ -88,17 +72,6 @@ protected void Init() m_OnlineSceneLabel = new GUIContent("Online Scene", "The scene loaded when the network comes online (connected to server)"); m_DontDestroyOnLoadLabel = new GUIContent("Don't Destroy on Load", "Enable to persist the NetworkManager across scene changes."); m_RunInBackgroundLabel = new GUIContent("Run in Background", "Enable to ensure that the application runs when it does not have focus.\n\nThis is required when testing multiple instances on a single machine, but not recommended for shipping on mobile platforms."); - - m_MaxConnectionsLabel = new GUIContent("Max Connections", "Maximum number of network connections"); - m_MinUpdateTimeoutLabel = new GUIContent("Min Update Timeout", "Minimum time network thread waits for events"); - m_ConnectTimeoutLabel = new GUIContent("Connect Timeout", "Time to wait for timeout on connecting"); - m_DisconnectTimeoutLabel = new GUIContent("Disconnect Timeout", "Time to wait for detecting disconnect"); - m_PingTimeoutLabel = new GUIContent("Ping Timeout", "Time to wait for ping messages"); - - m_ThreadAwakeTimeoutLabel = new GUIContent("Thread Awake Timeout", "The minimum time period when system will check if there are any messages for send (or receive)."); - m_ReactorModelLabel = new GUIContent("Reactor Model", "Defines reactor model for the network library"); - m_ReactorMaximumReceivedMessagesLabel = new GUIContent("Reactor Max Recv Messages", "Defines maximum amount of messages in the receive queue"); - m_ReactorMaximumSentMessagesLabel = new GUIContent("Reactor Max Sent Messages", "Defines maximum message count in sent queue"); m_UseWebSocketsLabel = new GUIContent("Use WebSockets", "This makes the server listen for connections using WebSockets. This allows WebGL clients to connect to the server."); m_NetworkAddressLabel = new GUIContent("Network Address", "The network address currently in use."); @@ -137,19 +110,6 @@ protected void Init() m_SpawnList.onAddCallback = AddButton; m_SpawnList.elementHeight = 16; // this uses a 16x16 icon. other sizes make it stretch. - // network configuration - m_CustomConfigProperty = serializedObject.FindProperty("m_CustomConfig"); - m_ChannelListProperty = serializedObject.FindProperty("m_Channels"); - m_ChannelList = new ReorderableList(serializedObject, m_ChannelListProperty); - m_ChannelList.drawHeaderCallback = ChannelDrawHeader; - m_ChannelList.drawElementCallback = ChannelDrawChild; - m_ChannelList.onReorderCallback = ChannelChanged; - m_ChannelList.onAddDropdownCallback = ChannelAddButton; - m_ChannelList.onRemoveCallback = ChannelRemoveButton; - m_ChannelList.onChangedCallback = ChannelChanged; - m_ChannelList.onReorderCallback = ChannelChanged; - m_ChannelList.onAddCallback = ChannelChanged; - // web sockets m_UseWebSocketsProperty = serializedObject.FindProperty("m_UseWebSockets"); } @@ -162,71 +122,6 @@ static void ShowPropertySuffix(GUIContent content, SerializedProperty prop, stri EditorGUILayout.EndHorizontal(); } - protected void ShowConfigInfo() - { - bool oldCustomConfig = m_NetworkManager.customConfig; - EditorGUILayout.PropertyField(m_CustomConfigProperty, m_AdvancedConfigurationLabel); - - // Populate default channels first time a custom config is created. - if (m_CustomConfigProperty.boolValue) - { - if (!oldCustomConfig) - { - if (m_NetworkManager.channels.Count == 0) - { - m_NetworkManager.channels.Add(QosType.ReliableSequenced); - m_NetworkManager.channels.Add(QosType.Unreliable); - m_NetworkManager.customConfig = true; - m_CustomConfigProperty.serializedObject.Update(); - m_ChannelList.serializedProperty.serializedObject.Update(); - } - } - } - - if (m_NetworkManager.customConfig) - { - EditorGUI.indentLevel += 1; - var maxConn = serializedObject.FindProperty("m_MaxConnections"); - ShowPropertySuffix(m_MaxConnectionsLabel, maxConn, "connections"); - - m_ChannelList.DoLayoutList(); - - maxConn.isExpanded = EditorGUILayout.Foldout(maxConn.isExpanded, "Timeouts"); - if (maxConn.isExpanded) - { - EditorGUI.indentLevel += 1; - var minUpdateTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_MinUpdateTimeout"); - var connectTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_ConnectTimeout"); - var disconnectTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_DisconnectTimeout"); - var pingTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_PingTimeout"); - - ShowPropertySuffix(m_MinUpdateTimeoutLabel, minUpdateTimeout, "millisec"); - ShowPropertySuffix(m_ConnectTimeoutLabel, connectTimeout, "millisec"); - ShowPropertySuffix(m_DisconnectTimeoutLabel, disconnectTimeout, "millisec"); - ShowPropertySuffix(m_PingTimeoutLabel, pingTimeout, "millisec"); - EditorGUI.indentLevel -= 1; - } - - var threadAwakeTimeout = serializedObject.FindProperty("m_GlobalConfig.m_ThreadAwakeTimeout"); - threadAwakeTimeout.isExpanded = EditorGUILayout.Foldout(threadAwakeTimeout.isExpanded, "Global Config"); - if (threadAwakeTimeout.isExpanded) - { - EditorGUI.indentLevel += 1; - var reactorModel = serializedObject.FindProperty("m_GlobalConfig.m_ReactorModel"); - var reactorMaximumReceivedMessages = serializedObject.FindProperty("m_GlobalConfig.m_ReactorMaximumReceivedMessages"); - var reactorMaximumSentMessages = serializedObject.FindProperty("m_GlobalConfig.m_ReactorMaximumSentMessages"); - - ShowPropertySuffix(m_ThreadAwakeTimeoutLabel, threadAwakeTimeout, "millisec"); - EditorGUILayout.PropertyField(reactorModel, m_ReactorModelLabel); - ShowPropertySuffix(m_ReactorMaximumReceivedMessagesLabel, reactorMaximumReceivedMessages, "messages"); - ShowPropertySuffix(m_ReactorMaximumSentMessagesLabel, reactorMaximumSentMessages, "messages"); - EditorGUI.indentLevel -= 1; - } - - EditorGUI.indentLevel -= 1; - } - } - protected void ShowSpawnInfo() { m_PlayerPrefabProperty.isExpanded = EditorGUILayout.Foldout(m_PlayerPrefabProperty.isExpanded, m_ShowSpawnLabel); @@ -415,7 +310,6 @@ public override void OnInspectorGUI() ShowScenes(); ShowNetworkInfo(); ShowSpawnInfo(); - ShowConfigInfo(); serializedObject.ApplyModifiedProperties(); ShowDerivedProperties(typeof(NetworkManager), null); @@ -489,51 +383,6 @@ internal void RemoveButton(ReorderableList list) list.index = m_SpawnListProperty.arraySize - 1; } } - - // List widget functions - - static void ChannelDrawHeader(Rect headerRect) - { - GUI.Label(headerRect, "Qos Channels:"); - } - - internal void ChannelDrawChild(Rect r, int index, bool isActive, bool isFocused) - { - QosType qos = (QosType)m_ChannelListProperty.GetArrayElementAtIndex(index).enumValueIndex; - QosType newValue = (QosType)EditorGUI.EnumPopup(r, "Channel #" + index, qos); - if (newValue != qos) - { - var obj = m_ChannelListProperty.GetArrayElementAtIndex(index); - obj.enumValueIndex = (int)newValue; - } - } - - internal void ChannelChanged(ReorderableList list) - { - EditorUtility.SetDirty(target); - } - - internal void ChannelAddButton(Rect rect, ReorderableList list) - { - m_ChannelListProperty.arraySize += 1; - var obj = m_ChannelListProperty.GetArrayElementAtIndex(m_ChannelListProperty.arraySize - 1); - obj.enumValueIndex = (int)QosType.ReliableSequenced; - list.index = m_ChannelListProperty.arraySize - 1; - } - - internal void ChannelRemoveButton(ReorderableList list) - { - if (m_NetworkManager.channels.Count == 1) - { - if (LogFilter.logError) { Debug.LogError("Cannot remove channel. There must be at least one QoS channel."); } - return; - } - m_ChannelListProperty.DeleteArrayElementAtIndex(m_ChannelList.index); - if (list.index >= m_ChannelListProperty.arraySize - 1) - { - list.index = m_ChannelListProperty.arraySize - 1; - } - } } } #endif //ENABLE_UNET diff --git a/Unity-Technologies-networking/Runtime/ClientScene.cs b/Unity-Technologies-networking/Runtime/ClientScene.cs index 080509366..e33da4bd0 100644 --- a/Unity-Technologies-networking/Runtime/ClientScene.cs +++ b/Unity-Technologies-networking/Runtime/ClientScene.cs @@ -580,7 +580,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg) { UpdateVarsMessage message = netMsg.ReadMessage(); - if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId + " channel:" + netMsg.channelId); } + if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject)) diff --git a/Unity-Technologies-networking/Runtime/CustomAttributes.cs b/Unity-Technologies-networking/Runtime/CustomAttributes.cs index 4fd9c6e8c..ba299cdf7 100644 --- a/Unity-Technologies-networking/Runtime/CustomAttributes.cs +++ b/Unity-Technologies-networking/Runtime/CustomAttributes.cs @@ -7,7 +7,6 @@ namespace UnityEngine.Networking [AttributeUsage(AttributeTargets.Class)] public class NetworkSettingsAttribute : Attribute { - public int channel = Channels.DefaultReliable; public float sendInterval = 0.1f; } @@ -20,26 +19,22 @@ public class SyncVarAttribute : Attribute [AttributeUsage(AttributeTargets.Method)] public class CommandAttribute : Attribute { - public int channel = Channels.DefaultReliable; // this is zero } [AttributeUsage(AttributeTargets.Method)] public class ClientRpcAttribute : Attribute { - public int channel = Channels.DefaultReliable; // this is zero } [AttributeUsage(AttributeTargets.Method)] public class TargetRpcAttribute : Attribute { - public int channel = Channels.DefaultReliable; // this is zero } [AttributeUsage(AttributeTargets.Event)] public class SyncEventAttribute : Attribute { - public int channel = Channels.DefaultReliable; // this is zero } [AttributeUsage(AttributeTargets.Method)] diff --git a/Unity-Technologies-networking/Runtime/LocalClient.cs b/Unity-Technologies-networking/Runtime/LocalClient.cs index 523dfe0b0..9b67d58ed 100644 --- a/Unity-Technologies-networking/Runtime/LocalClient.cs +++ b/Unity-Technologies-networking/Runtime/LocalClient.cs @@ -10,7 +10,6 @@ struct InternalMsg { internal ushort msgType; internal byte[] content; - internal int channelId; } List m_InternalMsgs = new List(); @@ -68,12 +67,11 @@ internal void AddLocalPlayer(PlayerController localPlayer) ClientScene.InternalAddPlayer(uv, localPlayer.playerControllerId); } - private void PostInternalMessage(short msgType, byte[] content, int channelId) + private void PostInternalMessage(short msgType, byte[] content) { InternalMsg msg = new InternalMsg(); msg.msgType = (ushort)msgType; msg.content = content; - msg.channelId = channelId; m_InternalMsgs.Add(msg); } @@ -81,7 +79,7 @@ private void PostInternalMessage(short msgType) { // call PostInternalMessage with empty content array if we just want to call a message like Connect // -> NetworkTransport has empty [] and not null array for those messages too - PostInternalMessage(msgType, new byte[0], 0); + PostInternalMessage(msgType, new byte[0]); } private void ProcessInternalMessages() @@ -103,7 +101,6 @@ private void ProcessInternalMessages() NetworkMessage internalMessage = new NetworkMessage(); internalMessage.msgType = (short)msg.msgType; internalMessage.reader = new NetworkReader(msg.content); - internalMessage.channelId = msg.channelId; internalMessage.conn = connection; m_Connection.InvokeHandler(internalMessage); @@ -120,14 +117,14 @@ private void ProcessInternalMessages() } // called by the server, to bypass network - internal void InvokeBytesOnClient(byte[] buffer, int channelId) + internal void InvokeBytesOnClient(byte[] buffer) { // unpack message and post to internal list for processing ushort msgType; byte[] content; if (Protocol.UnpackMessage(buffer, out msgType, out content)) { - PostInternalMessage((short)msgType, content, channelId); + PostInternalMessage((short)msgType, content); } else if (LogFilter.logError) Debug.LogError("InvokeBytesOnClient failed to unpack message: " + BitConverter.ToString(buffer)); } diff --git a/Unity-Technologies-networking/Runtime/LocalConnections.cs b/Unity-Technologies-networking/Runtime/LocalConnections.cs index c4f3efb8b..abd214a92 100644 --- a/Unity-Technologies-networking/Runtime/LocalConnections.cs +++ b/Unity-Technologies-networking/Runtime/LocalConnections.cs @@ -18,9 +18,9 @@ public ULocalConnectionToClient(LocalClient localClient) m_LocalClient = localClient; } - protected override bool SendBytes(byte[] bytes, int channelId) + protected override bool SendBytes(byte[] bytes) { - m_LocalClient.InvokeBytesOnClient(bytes, channelId); + m_LocalClient.InvokeBytesOnClient(bytes); return true; } } @@ -34,14 +34,14 @@ public ULocalConnectionToServer() address = "localServer"; } - protected override bool SendBytes(byte[] bytes, int channelId) + protected override bool SendBytes(byte[] bytes) { if (bytes.Length == 0) { if (LogFilter.logError) { Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); } return false; } - return NetworkServer.InvokeBytes(this, bytes, channelId); + return NetworkServer.InvokeBytes(this, bytes); } } } diff --git a/Unity-Technologies-networking/Runtime/NetworkBehaviour.cs b/Unity-Technologies-networking/Runtime/NetworkBehaviour.cs index 7a68841a8..fe780afae 100644 --- a/Unity-Technologies-networking/Runtime/NetworkBehaviour.cs +++ b/Unity-Technologies-networking/Runtime/NetworkBehaviour.cs @@ -53,7 +53,7 @@ NetworkIdentity myView // ----------------------------- Commands -------------------------------- [EditorBrowsable(EditorBrowsableState.Never)] - protected void SendCommandInternal(int cmdHash, NetworkWriter writer, int channelId, string cmdName) + protected void SendCommandInternal(int cmdHash, NetworkWriter writer, string cmdName) { // local players can always send commands, regardless of authority, other objects must have authority. if (!(isLocalPlayer || hasAuthority)) @@ -74,7 +74,7 @@ protected void SendCommandInternal(int cmdHash, NetworkWriter writer, int channe message.cmdHash = cmdHash; message.payload = writer.ToArray(); - ClientScene.readyConnection.SendByChannel((short)MsgType.Command, message, channelId); + ClientScene.readyConnection.Send((short)MsgType.Command, message); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -86,7 +86,7 @@ public virtual bool InvokeCommand(int cmdHash, NetworkReader reader) // ----------------------------- Client RPCs -------------------------------- [EditorBrowsable(EditorBrowsableState.Never)] - protected void SendRPCInternal(int rpcHash, NetworkWriter writer, int channelId, string rpcName) + protected void SendRPCInternal(int rpcHash, NetworkWriter writer, string rpcName) { // This cannot use NetworkServer.active, as that is not specific to this object. if (!isServer) @@ -101,11 +101,11 @@ protected void SendRPCInternal(int rpcHash, NetworkWriter writer, int channelId, message.rpcHash = rpcHash; message.payload = writer.ToArray(); - NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.Rpc, message, channelId); + NetworkServer.SendToReady(gameObject, (short)MsgType.Rpc, message); } [EditorBrowsable(EditorBrowsableState.Never)] - protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, NetworkWriter writer, int channelId, string rpcName) + protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, NetworkWriter writer, string rpcName) { // This cannot use NetworkServer.active, as that is not specific to this object. if (!isServer) @@ -120,7 +120,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, Networ message.rpcHash = rpcHash; message.payload = writer.ToArray(); - conn.SendByChannel((short)MsgType.Rpc, message, channelId); + conn.Send((short)MsgType.Rpc, message); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -132,7 +132,7 @@ public virtual bool InvokeRPC(int cmdHash, NetworkReader reader) // ----------------------------- Sync Events -------------------------------- [EditorBrowsable(EditorBrowsableState.Never)] - protected void SendEventInternal(int eventHash, NetworkWriter writer, int channelId, string eventName) + protected void SendEventInternal(int eventHash, NetworkWriter writer, string eventName) { if (!NetworkServer.active) { @@ -146,7 +146,7 @@ protected void SendEventInternal(int eventHash, NetworkWriter writer, int channe message.eventHash = eventHash; message.payload = writer.ToArray(); - NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.SyncEvent, message, channelId); + NetworkServer.SendToReady(gameObject, (short)MsgType.SyncEvent, message); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -587,11 +587,6 @@ public virtual bool OnCheckObserver(NetworkConnection conn) return true; } - public virtual int GetNetworkChannel() - { - return Channels.DefaultReliable; - } - public virtual float GetNetworkSendInterval() { return k_DefaultSendInterval; diff --git a/Unity-Technologies-networking/Runtime/NetworkClient.cs b/Unity-Technologies-networking/Runtime/NetworkClient.cs index 6e402952e..32871e5aa 100644 --- a/Unity-Technologies-networking/Runtime/NetworkClient.cs +++ b/Unity-Technologies-networking/Runtime/NetworkClient.cs @@ -17,7 +17,6 @@ public class NetworkClient public static List allClients { get { return s_Clients; } } public static bool active { get { return s_IsActive; } } - HostTopology m_HostTopology; int m_HostPort; string m_ServerIp = ""; @@ -47,8 +46,6 @@ internal void SetHandlers(NetworkConnection conn) public NetworkConnection connection { get { return m_Connection; } } public Dictionary handlers { get { return m_MessageHandlers; } } - public int numChannels { get { return m_HostTopology.DefaultConfig.ChannelCount; } } - public HostTopology hostTopology { get { return m_HostTopology; }} public int hostPort { get { return m_HostPort; } @@ -91,20 +88,6 @@ public NetworkClient(NetworkConnection conn) RegisterSystemHandlers(false); } - public bool Configure(ConnectionConfig config, int maxConnections) - { - HostTopology top = new HostTopology(config, maxConnections); - return Configure(top); - } - - public bool Configure(HostTopology topology) - { - //NOTE: this maxConnections is across all clients that use this tuner, so it is - // effectively the number of _clients_. - m_HostTopology = topology; - return true; - } - static bool IsValidIpV6(string address) { // use C# built-in method @@ -129,23 +112,13 @@ public void Connect(string serverIp, int serverPort) m_ClientConnectionId = 0; m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); - m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); + m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId); } void PrepareForConnect(bool usePlatformSpecificProtocols) { SetActive(true); RegisterSystemHandlers(false); - - if (m_HostTopology == null) - { - var config = new ConnectionConfig(); - config.AddChannel(QosType.ReliableSequenced); - config.AddChannel(QosType.Unreliable); - config.UsePlatformSpecificProtocols = usePlatformSpecificProtocols; - m_HostTopology = new HostTopology(config, 8); - } - m_ClientId = 0; // NetworkTransport.AddHost 'Returns the ID of the host that was created.' } @@ -162,22 +135,20 @@ public virtual void Disconnect() } } - public bool SendByChannel(short msgType, MessageBase msg, int channelId) + public bool Send(short msgType, MessageBase msg) { if (m_Connection != null) { if (connectState != ConnectState.Connected) { - if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel when not connected to a server"); } + if (LogFilter.logError) { Debug.LogError("NetworkClient Send when not connected to a server"); } return false; } - return m_Connection.SendByChannel(msgType, msg, channelId); + return m_Connection.Send(msgType, msg); } - if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel with no connection"); } + if (LogFilter.logError) { Debug.LogError("NetworkClient Send with no connection"); } return false; } - public bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); } - public bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); } public void Shutdown() { @@ -224,7 +195,7 @@ internal virtual void Update() break; case Telepathy.EventType.Data: Debug.Log("NetworkClient loop: Data: " + BitConverter.ToString(msg.data)); - m_Connection.TransportReceive(msg.data, 0); + m_Connection.TransportReceive(msg.data); break; case Telepathy.EventType.Disconnected: Debug.Log("NetworkClient loop: Disconnected"); @@ -277,7 +248,6 @@ void GenerateError(byte error) netMsg.msgType = (short)MsgType.Error; netMsg.reader = new NetworkReader(writer.ToArray()); netMsg.conn = m_Connection; - netMsg.channelId = 0; msgDelegate(netMsg); } } diff --git a/Unity-Technologies-networking/Runtime/NetworkConnection.cs b/Unity-Technologies-networking/Runtime/NetworkConnection.cs index e2efac984..ae8aab12b 100644 --- a/Unity-Technologies-networking/Runtime/NetworkConnection.cs +++ b/Unity-Technologies-networking/Runtime/NetworkConnection.cs @@ -34,14 +34,11 @@ public class NetworkConnection : IDisposable public NetworkError lastError { get { return error; } internal set { error = value; } } - public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology) + public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId) { address = networkAddress; hostId = networkHostId; connectionId = networkConnectionId; - - if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2)) - throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); } ~NetworkConnection() @@ -99,10 +96,10 @@ internal void SetHandlers(Dictionary handlers) public bool InvokeHandlerNoData(short msgType) { - return InvokeHandler(msgType, null, 0); + return InvokeHandler(msgType, null); } - public bool InvokeHandler(short msgType, NetworkReader reader, int channelId) + public bool InvokeHandler(short msgType, NetworkReader reader) { NetworkMessageDelegate msgDelegate; if (m_MessageHandlers.TryGetValue(msgType, out msgDelegate)) @@ -111,7 +108,6 @@ public bool InvokeHandler(short msgType, NetworkReader reader, int channelId) message.msgType = msgType; message.conn = this; message.reader = reader; - message.channelId = channelId; msgDelegate(message); return true; @@ -177,39 +173,37 @@ internal bool GetPlayerController(short playerControllerId, out PlayerController return playerController != null; } - public virtual bool SendByChannel(short msgType, MessageBase msg, int channelId) + public virtual bool Send(short msgType, MessageBase msg) { NetworkWriter writer = new NetworkWriter(); msg.Serialize(writer); // pack message and send byte[] message = Protocol.PackMessage((ushort)msgType, writer.ToArray()); - return SendBytes(message, channelId); + return SendBytes(message); } - public virtual bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); } - public virtual bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); } // protected because no one except NetworkConnection should ever send bytes directly to the client, as they // would be detected as some kind of message. send messages instead. - protected virtual bool SendBytes(byte[] bytes, int channelId) + protected virtual bool SendBytes(byte[] bytes) { if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); } if (bytes.Length > UInt16.MaxValue) { - if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); } + if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); } return false; } if (bytes.Length == 0) { // zero length packets getting into the packet queues are bad. - if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes"); } + if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send zero bytes"); } return false; } byte error; - return TransportSend(bytes, channelId, out error); + return TransportSend(bytes, out error); } // handle this message @@ -219,7 +213,7 @@ protected virtual bool SendBytes(byte[] bytes, int channelId) // -> in other words, we always receive 1 message per NetworkTransport.Receive call, never two. // -> can be tested easily with a 1000ms send delay and then logging amount received in while loops here // and in NetworkServer/Client Update. HandleBytes already takes exactly one. - protected void HandleBytes(byte[] buffer, int channelId) + protected void HandleBytes(byte[] buffer) { // unpack message ushort msgType; @@ -236,7 +230,6 @@ protected void HandleBytes(byte[] buffer, int channelId) msg.msgType = (short)msgType; msg.reader = new NetworkReader(content); msg.conn = this; - msg.channelId = channelId; // add to queue while paused, otherwise process directly if (pauseQueue != null) @@ -308,12 +301,12 @@ internal void RemoveObservers() m_VisList.Clear(); } - public virtual void TransportReceive(byte[] bytes, int channelId) + public virtual void TransportReceive(byte[] bytes) { - HandleBytes(bytes, channelId); + HandleBytes(bytes); } - public virtual bool TransportSend(byte[] bytes, int channelId, out byte error) + public virtual bool TransportSend(byte[] bytes, out byte error) { error = 0; if (Transport.client.Connected) diff --git a/Unity-Technologies-networking/Runtime/NetworkIdentity.cs b/Unity-Technologies-networking/Runtime/NetworkIdentity.cs index e7462e08e..31bc53178 100644 --- a/Unity-Technologies-networking/Runtime/NetworkIdentity.cs +++ b/Unity-Technologies-networking/Runtime/NetworkIdentity.cs @@ -433,7 +433,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo // original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might // be useful for debugging. - if (bytes.Length > NetworkServer.maxPacketSize) + if (bytes.Length > Transport.MaxPacketSize) { if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); } } @@ -443,9 +443,9 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo return result; } - // serialize all components (or only dirty ones for channelId if not initial state) + // serialize all components (or only dirty ones if not initial state) // -> returns TRUE if any date other than dirtyMask was written! - internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter writer, bool initialState, int channelId) + internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter writer, bool initialState) { if (components.Length > 64) { @@ -458,17 +458,17 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter NetworkWriter payload = new NetworkWriter(); for (int i = 0; i < components.Length; ++i) { - // is this component dirty on this channel? - // -> always serialize if initialState so all components with all channels are included in spawn packet + // is this component dirty? + // -> always serialize if initialState so all components are included in spawn packet // -> note: IsDirty() is false if the component isn't dirty or sendInterval isn't elapsed yet NetworkBehaviour comp = m_NetworkBehaviours[i]; - if (initialState || (comp.IsDirty() && comp.GetNetworkChannel() == channelId)) + if (initialState || comp.IsDirty()) { // set bit #i to 1 in dirty mask dirtyComponentsMask |= (ulong)(1L << i); // serialize the data - if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState + " channelId=" + channelId); } + if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState); } OnSerializeSafely(comp, payload, initialState); // Clear dirty bits only if we are synchronizing data and not sending a spawn message. @@ -494,7 +494,7 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter } // extra version that uses m_NetworkBehaviours so we can call it from the outside - internal void OnSerializeAllSafely(NetworkWriter writer, bool initialState, int channelId) { OnSerializeAllSafely(m_NetworkBehaviours, writer, initialState, channelId); } + internal void OnSerializeAllSafely(NetworkWriter writer, bool initialState) { OnSerializeAllSafely(m_NetworkBehaviours, writer, initialState); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -721,20 +721,16 @@ internal void HandleRPC(int cmdHash, NetworkReader reader) // invoked by unity runtime immediately after the regular "Update()" function. internal void UNetUpdate() { - // go through each channel - for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++) + // serialize all the dirty components and send (if any were dirty) + NetworkWriter writer = new NetworkWriter(); + if (OnSerializeAllSafely(m_NetworkBehaviours, writer, false)) { - // serialize all the dirty components and send (if any were dirty) - NetworkWriter writer = new NetworkWriter(); - if (OnSerializeAllSafely(m_NetworkBehaviours, writer, false, channelId)) - { - // construct message and send - UpdateVarsMessage message = new UpdateVarsMessage(); - message.netId = netId; - message.payload = writer.ToArray(); + // construct message and send + UpdateVarsMessage message = new UpdateVarsMessage(); + message.netId = netId; + message.payload = writer.ToArray(); - NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.UpdateVars, message, channelId); - } + NetworkServer.SendToReady(gameObject, (short)MsgType.UpdateVars, message); } } diff --git a/Unity-Technologies-networking/Runtime/NetworkManager.cs b/Unity-Technologies-networking/Runtime/NetworkManager.cs index d60d48109..77e8606e7 100644 --- a/Unity-Technologies-networking/Runtime/NetworkManager.cs +++ b/Unity-Technologies-networking/Runtime/NetworkManager.cs @@ -37,11 +37,7 @@ public class NetworkManager : MonoBehaviour [SerializeField] string m_OnlineScene = ""; [SerializeField] List m_SpawnPrefabs = new List(); - [SerializeField] bool m_CustomConfig; [SerializeField] int m_MaxConnections = 4; - [SerializeField] ConnectionConfig m_ConnectionConfig; - [SerializeField] GlobalConfig m_GlobalConfig; - [SerializeField] List m_Channels = new List(); [SerializeField] bool m_UseWebSockets; @@ -76,11 +72,7 @@ public class NetworkManager : MonoBehaviour public List startPositions { get { return s_StartPositions; }} - public bool customConfig { get { return m_CustomConfig; } set { m_CustomConfig = value; } } - public ConnectionConfig connectionConfig { get { if (m_ConnectionConfig == null) { m_ConnectionConfig = new ConnectionConfig(); } return m_ConnectionConfig; } } - public GlobalConfig globalConfig { get { if (m_GlobalConfig == null) { m_GlobalConfig = new GlobalConfig(); } return m_GlobalConfig; } } public int maxConnections { get { return m_MaxConnections; } set { m_MaxConnections = value; } } - public List channels { get { return m_Channels; } } public bool useWebSockets { get { return m_UseWebSockets; } set { m_UseWebSockets = value; } } @@ -201,35 +193,6 @@ void OnValidate() if (LogFilter.logError) { Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); } m_PlayerPrefab = null; } - - if (m_ConnectionConfig != null && m_ConnectionConfig.MinUpdateTimeout <= 0) - { - if (LogFilter.logError) { Debug.LogError("NetworkManager MinUpdateTimeout cannot be zero or less. The value will be reset to 1 millisecond"); } - m_ConnectionConfig.MinUpdateTimeout = 1; - } - - if (m_GlobalConfig != null) - { - if (m_GlobalConfig.ThreadAwakeTimeout <= 0) - { - if (LogFilter.logError) { Debug.LogError("NetworkManager ThreadAwakeTimeout cannot be zero or less. The value will be reset to 1 millisecond"); } - m_GlobalConfig.ThreadAwakeTimeout = 1; - } - } - - // vis2k - // Channels.DefaultReliable = 0 and Unreliable = 1, so we have to - // force some kind of reliable to channel 0 and unreliable to 1. - // Otherwise the HLAPI code will assume a wrong channel for a lot of - // built-in functions. - // - // Changing them would result in chaos. Using anything != Fragmented - // would fail to send bigger messages too. - if (channels.Count < 1 || !Channels.IsReliableQoS(channels[0])) - Debug.LogWarning("NetworkManager: First channel needs to be Reliable because in the code Channels.DefaultReliable is 0."); - - if (channels.Count < 2 || !Channels.IsUnreliableQoS(channels[1])) - Debug.LogWarning("NetworkManager: Second channel needs to be Unreliable because in the code Channels.DefaultReliable is 1."); } internal void RegisterServerMessages() @@ -244,10 +207,10 @@ internal void RegisterServerMessages() public bool StartServer() { - return StartServer(null, -1); + return StartServer(-1); } - bool StartServer(ConnectionConfig config, int maxConnections) + bool StartServer(int maxConnections) { InitializeSingleton(); @@ -258,27 +221,6 @@ bool StartServer(ConnectionConfig config, int maxConnections) NetworkServer.useWebSockets = m_UseWebSockets; - if (m_GlobalConfig != null) - { - //NetworkTransport.Init(m_GlobalConfig); - } - - // passing a config overrides setting the connectionConfig property - if (m_CustomConfig && m_ConnectionConfig != null && config == null) - { - m_ConnectionConfig.Channels.Clear(); - for (int channelId = 0; channelId < m_Channels.Count; channelId++) - { - m_ConnectionConfig.AddChannel(m_Channels[channelId]); - } - NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections); - } - - if (config != null) - { - NetworkServer.Configure(config, maxConnections); - } - if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress)) { if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort)) @@ -365,7 +307,7 @@ public void UseExternalClient(NetworkClient externalClient) s_Address = m_NetworkAddress; } - public NetworkClient StartClient(ConnectionConfig config, int hostPort) + public NetworkClient StartClient(int hostPort) { InitializeSingleton(); @@ -374,36 +316,9 @@ public NetworkClient StartClient(ConnectionConfig config, int hostPort) isNetworkActive = true; - if (m_GlobalConfig != null) - { - //NetworkTransport.Init(m_GlobalConfig); - } - client = new NetworkClient(); client.hostPort = hostPort; - if (config != null) - { - if ((config.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2)) - throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); - - client.Configure(config, 1); - } - else - { - if (m_CustomConfig && m_ConnectionConfig != null) - { - m_ConnectionConfig.Channels.Clear(); - for (int i = 0; i < m_Channels.Count; i++) - { - m_ConnectionConfig.AddChannel(m_Channels[i]); - } - if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2)) - throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); - client.Configure(m_ConnectionConfig, m_MaxConnections); - } - } - RegisterClientMessages(client); if (string.IsNullOrEmpty(m_NetworkAddress)) @@ -422,18 +337,13 @@ public NetworkClient StartClient(ConnectionConfig config, int hostPort) public NetworkClient StartClient() { - return StartClient(null); + return StartClient(0); } - public NetworkClient StartClient(ConnectionConfig config) - { - return StartClient(config, 0); - } - - public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections) + public virtual NetworkClient StartHost(int maxConnections) { OnStartHost(); - if (StartServer(config, maxConnections)) + if (StartServer(maxConnections)) { var client = ConnectLocalClient(); OnServerConnect(client.connection); diff --git a/Unity-Technologies-networking/Runtime/NetworkServer.cs b/Unity-Technologies-networking/Runtime/NetworkServer.cs index dc5458456..7151dec35 100644 --- a/Unity-Technologies-networking/Runtime/NetworkServer.cs +++ b/Unity-Technologies-networking/Runtime/NetworkServer.cs @@ -22,13 +22,9 @@ public sealed class NetworkServer static int s_ServerHostId = -1; static int s_ServerPort = -1; - static HostTopology s_HostTopology; static bool s_UseWebSockets; static bool s_Initialized = false; - // this is cached here for easy access when checking the size of state update packets in NetworkIdentity - static internal ushort maxPacketSize; - // original HLAPI has .localConnections list with only m_LocalConnection in it // (for downwards compatibility because they removed the real localConnections list a while ago) // => removed it for easier code. use .localConection now! @@ -39,7 +35,6 @@ public sealed class NetworkServer public static List connections { get { return s_Connections; } } public static Dictionary handlers { get { return s_MessageHandlers; } } - public static HostTopology hostTopology { get { return s_HostTopology; }} public static Dictionary objects { get { return s_NetworkScene.localObjects; } } public static bool dontListen { get { return s_DontListen; } set { s_DontListen = value; } } @@ -47,7 +42,6 @@ public sealed class NetworkServer public static bool active { get { return s_Active; } } public static bool localClientActive { get { return s_LocalClientActive; } } - public static int numChannels { get { return s_HostTopology.DefaultConfig.ChannelCount; } } static Type s_NetworkConnectionClass = typeof(NetworkConnection); public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } } @@ -56,18 +50,6 @@ static public void SetNetworkConnectionClass() where T : NetworkConnection s_NetworkConnectionClass = typeof(T); } - static public bool Configure(ConnectionConfig config, int maxConnections) - { - HostTopology top = new HostTopology(config, maxConnections); - return Configure(top); - } - - static public bool Configure(HostTopology topology) - { - s_HostTopology = topology; - return true; - } - public static void Reset() { Debug.Log("NetworkServer.Reset calls NetworkTransport.Shutdown and Init"); @@ -104,14 +86,6 @@ public static void Initialize() s_Initialized = true; if (LogFilter.logDev) { Debug.Log("NetworkServer Created version " + Version.Current); } - if (s_HostTopology == null) - { - var config = new ConnectionConfig(); - config.AddChannel(QosType.ReliableSequenced); - config.AddChannel(QosType.Unreliable); - s_HostTopology = new HostTopology(config, 8); - } - if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); } } @@ -125,9 +99,6 @@ static internal void RegisterMessageHandlers() RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage); RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage); RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage); - - // also setup max packet size. - maxPacketSize = hostTopology.DefaultConfig.PacketSize; } static public bool Listen(int serverPort) @@ -171,7 +142,6 @@ static internal bool InternalListen(string ipAddress, int serverPort) if (LogFilter.logDebug) { Debug.Log("Server listen: " + ipAddress + ":" + s_ServerPort); } } - maxPacketSize = hostTopology.DefaultConfig.PacketSize; s_Active = true; RegisterMessageHandlers(); return true; @@ -279,25 +249,23 @@ static bool SendToObservers(GameObject contextObj, short msgType, MessageBase ms return false; } - static public bool SendByChannelToAll(short msgType, MessageBase msg, int channelId) + static public bool SendToAll(short msgType, MessageBase msg) { - if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToAll id:" + msgType); } + if (LogFilter.logDev) { Debug.Log("Server.SendToAll id:" + msgType); } bool result = true; for (int i = 0; i < connections.Count; i++) { NetworkConnection conn = connections[i]; if (conn != null) - result &= conn.SendByChannel(msgType, msg, channelId); + result &= conn.Send(msgType, msg); } return result; } - static public bool SendToAll(short msgType, MessageBase msg) { return SendByChannelToAll(msgType, msg, Channels.DefaultReliable); } - static public bool SendUnreliableToAll(short msgType, MessageBase msg) { return SendByChannelToAll(msgType, msg, Channels.DefaultUnreliable); } - static public bool SendByChannelToReady(GameObject contextObj, short msgType, MessageBase msg, int channelId) + static public bool SendToReady(GameObject contextObj, short msgType, MessageBase msg) { - if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToReady msgType:" + msgType); } + if (LogFilter.logDev) { Debug.Log("Server.SendToReady msgType:" + msgType); } if (contextObj == null) { @@ -307,7 +275,7 @@ static public bool SendByChannelToReady(GameObject contextObj, short msgType, Me NetworkConnection conn = connections[i]; if (conn != null && conn.isReady) { - conn.SendByChannel(msgType, msg, channelId); + conn.Send(msgType, msg); } } return true; @@ -322,15 +290,13 @@ static public bool SendByChannelToReady(GameObject contextObj, short msgType, Me NetworkConnection conn = uv.observers[i]; if (conn.isReady) { - result &= conn.SendByChannel(msgType, msg, channelId); + result &= conn.Send(msgType, msg); } } return result; } return false; } - static public bool SendToReady(GameObject contextObj, short msgType, MessageBase msg) { return SendByChannelToReady(contextObj, msgType, msg, Channels.DefaultReliable); } - static public bool SendUnreliableToReady(GameObject contextObj, short msgType, MessageBase msg) { return SendByChannelToReady(contextObj, msgType, msg, Channels.DefaultUnreliable); } static public void DisconnectAll() { @@ -414,7 +380,7 @@ static internal void InternalUpdate() break; case Telepathy.EventType.Data: //Debug.Log(message.connectionId + " Data: " + BitConverter.ToString(message.data)); - HandleData((int)message.connectionId, message.data, 0, 0); + HandleData((int)message.connectionId, message.data, 0); break; case Telepathy.EventType.Disconnected: Console.WriteLine(message.connectionId + " Disconnected"); @@ -439,7 +405,7 @@ static void HandleConnect(int connectionId, byte error) // add player info NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass); conn.SetHandlers(s_MessageHandlers); - conn.Initialize("TODO_ADDRESS_FROM_TCP", s_ServerHostId, connectionId, s_HostTopology); + conn.Initialize("TODO_ADDRESS_FROM_TCP", s_ServerHostId, connectionId); conn.lastError = (NetworkError)0; // add connection at correct index @@ -509,7 +475,7 @@ public static NetworkConnection FindConnection(int connectionId) return s_Connections[connectionId]; } - static void HandleData(int connectionId, byte[] data, int channelId, byte error) + static void HandleData(int connectionId, byte[] data, byte error) { var conn = FindConnection(connectionId); if (conn == null) @@ -525,12 +491,12 @@ static void HandleData(int connectionId, byte[] data, int channelId, byte error) return; } - OnData(conn, data, channelId); + OnData(conn, data); } - static void OnData(NetworkConnection conn, byte[] data, int channelId) + static void OnData(NetworkConnection conn, byte[] data) { - conn.TransportReceive(data, channelId); + conn.TransportReceive(data); } static void GenerateConnectError(byte error) @@ -566,7 +532,7 @@ static void GenerateError(NetworkConnection conn, byte error) // pass a reader (attached to local buffer) to handler NetworkReader reader = new NetworkReader(writer.ToArray()); - conn.InvokeHandler((short)MsgType.Error, reader, 0); + conn.InvokeHandler((short)MsgType.Error, reader); } } @@ -1067,7 +1033,7 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn // serialize all components with initialState = true NetworkWriter writer = new NetworkWriter(); - uv.OnSerializeAllSafely(writer, true, -1); // channelId doesn't matter if initialState + uv.OnSerializeAllSafely(writer, true); msg.payload = writer.ToArray(); // conn is != null when spawning it for a client @@ -1091,7 +1057,7 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn // include synch data NetworkWriter writer = new NetworkWriter(); - uv.OnSerializeAllSafely(writer, true, -1); // channelId doesn't matter if initialState + uv.OnSerializeAllSafely(writer, true); msg.payload = writer.ToArray(); // conn is != null when spawning it for a client @@ -1321,7 +1287,7 @@ static public void UnSpawn(GameObject obj) UnSpawnObject(obj); } - static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, int channelId) + static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer) { ushort msgType; byte[] content; @@ -1330,7 +1296,7 @@ static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, i if (handlers.ContainsKey((short)msgType) && s_LocalConnection != null) { // this must be invoked with the connection to the client, not the client's connection to the server - s_LocalConnection.InvokeHandler((short)msgType, new NetworkReader(content), channelId); + s_LocalConnection.InvokeHandler((short)msgType, new NetworkReader(content)); return true; } } diff --git a/Unity-Technologies-networking/Runtime/NetworkTranformChild.cs b/Unity-Technologies-networking/Runtime/NetworkTranformChild.cs index ae60f4599..de7e1ded3 100644 --- a/Unity-Technologies-networking/Runtime/NetworkTranformChild.cs +++ b/Unity-Technologies-networking/Runtime/NetworkTranformChild.cs @@ -395,7 +395,7 @@ void SendTransform() m_PrevPosition = m_Target.localPosition; m_PrevRotation = m_Target.localRotation; - ClientScene.readyConnection.SendByChannel((short)MsgType.LocalChildTransform, message, GetNetworkChannel()); + ClientScene.readyConnection.Send((short)MsgType.LocalChildTransform, message); } static internal void HandleChildTransform(NetworkMessage netMsg) @@ -449,11 +449,6 @@ static internal void HandleChildTransform(NetworkMessage netMsg) } } - public override int GetNetworkChannel() - { - return Channels.DefaultUnreliable; - } - public override float GetNetworkSendInterval() { return m_SendInterval; diff --git a/Unity-Technologies-networking/Runtime/NetworkTransform.cs b/Unity-Technologies-networking/Runtime/NetworkTransform.cs index 2ec304bc2..d8ab355ae 100644 --- a/Unity-Technologies-networking/Runtime/NetworkTransform.cs +++ b/Unity-Technologies-networking/Runtime/NetworkTransform.cs @@ -1233,7 +1233,7 @@ void SendTransform() message.netId = netId; message.payload = writer.ToArray(); - ClientScene.readyConnection.SendByChannel((short)MsgType.LocalPlayerTransform, message, GetNetworkChannel()); + ClientScene.readyConnection.Send((short)MsgType.LocalPlayerTransform, message); } static public void HandleTransform(NetworkMessage netMsg) @@ -1557,11 +1557,6 @@ static public float UnserializeSpin2D(NetworkReader reader, CompressionSyncMode return ReadAngle(reader, compression); } - public override int GetNetworkChannel() - { - return Channels.DefaultUnreliable; - } - public override float GetNetworkSendInterval() { return m_SendInterval; diff --git a/Unity-Technologies-networking/Runtime/SyncList.cs b/Unity-Technologies-networking/Runtime/SyncList.cs index 7f2ab156d..a8fde613a 100644 --- a/Unity-Technologies-networking/Runtime/SyncList.cs +++ b/Unity-Technologies-networking/Runtime/SyncList.cs @@ -263,7 +263,7 @@ void SendMsg(Operation op, int itemIndex, T item) message.payload = writer.ToArray(); - NetworkServer.SendByChannelToReady(uv.gameObject, (short)MsgType.SyncList, message, m_Behaviour.GetNetworkChannel()); + NetworkServer.SendToReady(uv.gameObject, (short)MsgType.SyncList, message); // ensure it is invoked on host if (m_Behaviour.isServer && m_Behaviour.isClient && m_Callback != null) diff --git a/Unity-Technologies-networking/Runtime/Transport.cs b/Unity-Technologies-networking/Runtime/Transport.cs index c9943a474..df66f88db 100644 --- a/Unity-Technologies-networking/Runtime/Transport.cs +++ b/Unity-Technologies-networking/Runtime/Transport.cs @@ -7,6 +7,9 @@ public static class Transport public static Telepathy.Client client = new Telepathy.Client(); public static Telepathy.Server server = new Telepathy.Server(); + // hlapi needs to know max packet size to show warnings + public static int MaxPacketSize = ushort.MaxValue; + static Transport() { // tell Telepathy to use Unity's Debug.Log diff --git a/Unity-Technologies-networking/Runtime/UNetwork.cs b/Unity-Technologies-networking/Runtime/UNetwork.cs index 188ebf05c..a5090b423 100644 --- a/Unity-Technologies-networking/Runtime/UNetwork.cs +++ b/Unity-Technologies-networking/Runtime/UNetwork.cs @@ -63,7 +63,6 @@ public class NetworkMessage public short msgType; public NetworkConnection conn; public NetworkReader reader; - public int channelId; public static string Dump(byte[] payload, int sz) { @@ -94,28 +93,6 @@ public enum Version Current = 1 } - public class Channels - { - public const int DefaultReliable = 0; - public const int DefaultUnreliable = 1; - - // moved IsSequenced etc. functions here because it's better than in NetworkConnection - public static bool IsSequencedQoS(QosType qos) - { - return (qos == QosType.ReliableSequenced || qos == QosType.UnreliableSequenced); - } - - public static bool IsReliableQoS(QosType qos) - { - return (qos == QosType.Reliable || qos == QosType.ReliableFragmented || qos == QosType.ReliableSequenced || qos == QosType.ReliableStateUpdate); - } - - public static bool IsUnreliableQoS(QosType qos) - { - return (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced || qos == QosType.StateUpdate); - } - } - // network protocol all in one place, instead of constructing headers in all kinds of different places // // MsgType (1-n bytes) diff --git a/Unity-Technologies-networking/Weaver/UNetBehaviourProcessor.cs b/Unity-Technologies-networking/Weaver/UNetBehaviourProcessor.cs index 69c8898a8..0252ec505 100644 --- a/Unity-Technologies-networking/Weaver/UNetBehaviourProcessor.cs +++ b/Unity-Technologies-networking/Weaver/UNetBehaviourProcessor.cs @@ -27,7 +27,6 @@ class NetworkBehaviourProcessor List m_TargetRpcCallFuncs = new List(); const int k_SyncVarLimit = 64; // ulong = 64 bytes - int m_QosChannel; TypeDefinition m_td; int m_NetIdFieldCounter; @@ -527,7 +526,7 @@ void GenerateSerialization() if (m_SyncVars.Count == 0) { - + // generate: return dirtyLocal serWorker.Append(serWorker.Create(OpCodes.Ldloc_0)); serWorker.Append(serWorker.Create(OpCodes.Ret)); @@ -578,7 +577,7 @@ void GenerateSerialization() // generate a writer call for any dirty variable in this class // start at number of syncvars in parent - int dirtyBit = Weaver.GetSyncVarStart(m_td.BaseType.FullName); + int dirtyBit = Weaver.GetSyncVarStart(m_td.BaseType.FullName); foreach (FieldDefinition syncVar in m_SyncVars) { Instruction varLabel = serWorker.Create(OpCodes.Nop); @@ -594,7 +593,7 @@ void GenerateSerialization() serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); // writer serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base serWorker.Append(serWorker.Create(OpCodes.Ldfld, syncVar)); - + MethodReference writeFunc = Weaver.GetWriteFunc(syncVar.FieldType); if (writeFunc != null) { @@ -629,27 +628,6 @@ void GenerateSerialization() m_td.Methods.Add(serialize); } - - static int GetChannelId(FieldDefinition field) - { - int channel = 0; - foreach (var ca in field.CustomAttributes) - { - if (ca.AttributeType.FullName == Weaver.SyncVarType.FullName) - { - foreach (CustomAttributeNamedArgument customField in ca.Fields) - { - if (customField.Name == "channel") - { - channel = (int)customField.Argument.Value; - break; - } - } - } - } - return channel; - } - // returns false for error, not for no-hook-exists bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMethod) { @@ -694,20 +672,6 @@ bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMet return true; } - void GenerateNetworkChannelSetting(int channel) - { - MethodDefinition meth = new MethodDefinition("GetNetworkChannel", MethodAttributes.Public | - MethodAttributes.Virtual | - MethodAttributes.HideBySig, - Weaver.int32Type); - - ILProcessor worker = meth.Body.GetILProcessor(); - - worker.Append(worker.Create(OpCodes.Ldc_I4, channel)); - worker.Append(worker.Create(OpCodes.Ret)); - m_td.Methods.Add(meth); - } - void GenerateNetworkIntervalSetting(float interval) { MethodDefinition meth = new MethodDefinition("GetNetworkSendInterval", MethodAttributes.Public | @@ -732,22 +696,6 @@ void GenerateNetworkSettings() // generate virtual functions foreach (var field in ca.Fields) { - if (field.Name == "channel") - { - // 0 is Channels.DefaultChannel - if ((int)field.Argument.Value == 0) - continue; - - if (HasMethod("GetNetworkChannel")) - { - Log.Error( - "GetNetworkChannel, is already implemented, please make sure you either use NetworkSettings or GetNetworkChannel"); - Weaver.fail = true; - return; - } - m_QosChannel = (int)field.Argument.Value; - GenerateNetworkChannelSetting(m_QosChannel); - } if (field.Name == "sendInterval") { const float stdValue = 0.1f; @@ -1102,7 +1050,7 @@ public void CallCmdThrust(float thrusting, int spin) NetworkWriter networkWriter = new NetworkWriter(); networkWriter.Write(thrusting); networkWriter.WritePackedUInt32((uint)spin); - base.SendCommandInternal(ShipControl.kCmdCmdThrust, networkWriter, channelId, cmdName); + base.SendCommandInternal(ShipControl.kCmdCmdThrust, networkWriter, cmdName); } */ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca) @@ -1131,7 +1079,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca) WriteClientActiveCheck(cmdWorker, md.Name, label, "Command function"); // local client check - Instruction localClientLabel = cmdWorker.Create(OpCodes.Nop); cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0)); cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.UBehaviourIsServer)); @@ -1160,16 +1107,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca) if (!WriteArguments(cmdWorker, md, "Command", false)) return null; - // find channel for Command - int channel = 0; - foreach (var field in ca.Fields) - { - if (field.Name == "channel") - { - channel = (int)field.Argument.Value; - } - } - var cmdName = md.Name; int index = cmdName.IndexOf(k_CmdPrefix); if (index > -1) @@ -1181,7 +1118,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca) cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0)); // load 'base.' to call the SendCommand function with cmdWorker.Append(cmdWorker.Create(OpCodes.Ldsfld, cmdConstant)); // cmdHash cmdWorker.Append(cmdWorker.Create(OpCodes.Ldloc_0)); // writer - cmdWorker.Append(cmdWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable) cmdWorker.Append(cmdWorker.Create(OpCodes.Ldstr, cmdName)); cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.sendCommandInternal)); @@ -1259,7 +1195,7 @@ public void CallTargetTest (NetworkConnection conn, int param) } else { NetworkWriter writer = new NetworkWriter (); writer.WritePackedUInt32 ((uint)param); - base.SendTargetRPCInternal (conn, Player.kTargetRpcTargetTest, val, 0, "TargetTest"); + base.SendTargetRPCInternal (conn, Player.kTargetRpcTargetTest, val, "TargetTest"); } } */ @@ -1306,16 +1242,6 @@ MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca) if (!WriteArguments(rpcWorker, md, "TargetRPC", true)) return null; - // find channel for TargetRpc - int channel = 0; - foreach (var field in ca.Fields) - { - if (field.Name == "channel") - { - channel = (int)field.Argument.Value; - } - } - var rpcName = md.Name; int index = rpcName.IndexOf(k_TargetRpcPrefix); if (index > -1) @@ -1328,7 +1254,6 @@ MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca) rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_1)); // connection rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer - rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable) rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName)); rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendTargetRpcInternal)); @@ -1380,16 +1305,6 @@ MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca) if (!WriteArguments(rpcWorker, md, "RPC", false)) return null; - // find channel for Rpc - int channel = 0; - foreach (var field in ca.Fields) - { - if (field.Name == "channel") - { - channel = (int)field.Argument.Value; - } - } - var rpcName = md.Name; int index = rpcName.IndexOf(k_RpcPrefix); if (index > -1) @@ -1401,7 +1316,6 @@ MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca) rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_0)); // this rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer - rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable) rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName)); rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendRpcInternal)); @@ -1807,21 +1721,10 @@ MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttribute ca) if (!WriteArguments(evtWorker, invoke.Resolve(), "SyncEvent", false)) return null; - // find channel for ClientRpc - int channel = 0; - foreach (var field in ca.Fields) - { - if (field.Name == "channel") - { - channel = (int)field.Argument.Value; - } - } - // invoke interal send and return evtWorker.Append(evtWorker.Create(OpCodes.Ldarg_0)); // this evtWorker.Append(evtWorker.Create(OpCodes.Ldsfld, evtConstant)); // eventHash evtWorker.Append(evtWorker.Create(OpCodes.Ldloc_0)); // writer - evtWorker.Append(evtWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable) evtWorker.Append(evtWorker.Create(OpCodes.Ldstr, ed.Name)); evtWorker.Append(evtWorker.Create(OpCodes.Call, Weaver.sendEventInternal));