using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using UnityEngine; using UnityEngine.Bindings; using UnityEngine.Networking.Types; [assembly: InternalsVisibleTo("UnityEngine.UIElementsModule")] [assembly: InternalsVisibleTo("UnityEngine.UIElementsNativeModule")] [assembly: InternalsVisibleTo("UnityEngine.UIModule")] [assembly: InternalsVisibleTo("UnityEngine.TilemapModule")] [assembly: InternalsVisibleTo("UnityEngine.TextCoreTextEngineModule")] [assembly: InternalsVisibleTo("UnityEngine.TextCoreFontEngineModule")] [assembly: InternalsVisibleTo("UnityEngine.TerrainPhysicsModule")] [assembly: InternalsVisibleTo("UnityEngine.TerrainModule")] [assembly: InternalsVisibleTo("UnityEngine.SubsystemsModule")] [assembly: InternalsVisibleTo("UnityEngine.SubstanceModule")] [assembly: InternalsVisibleTo("UnityEngine.StreamingModule")] [assembly: InternalsVisibleTo("UnityEngine.SpriteShapeModule")] [assembly: InternalsVisibleTo("UnityEngine.SpriteMaskModule")] [assembly: InternalsVisibleTo("UnityEngine.ScreenCaptureModule")] [assembly: InternalsVisibleTo("UnityEngine.RuntimeInitializeOnLoadManagerInitializerModule")] [assembly: InternalsVisibleTo("UnityEngine.UmbraModule")] [assembly: InternalsVisibleTo("UnityEngine.UNETModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityCurlModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityTestProtocolModule")] [assembly: CompilationRelaxations(8)] [assembly: InternalsVisibleTo("UnityEngine.PS4VRModule")] [assembly: InternalsVisibleTo("UnityEngine.PS4Module")] [assembly: InternalsVisibleTo("UnityEngine.XboxOneModule")] [assembly: InternalsVisibleTo("UnityEngine.SwitchModule")] [assembly: InternalsVisibleTo("UnityEngine.WindModule")] [assembly: InternalsVisibleTo("UnityEngine.VRModule")] [assembly: InternalsVisibleTo("UnityEngine.ProfilerModule")] [assembly: InternalsVisibleTo("UnityEngine.XRModule")] [assembly: InternalsVisibleTo("UnityEngine.VideoModule")] [assembly: InternalsVisibleTo("UnityEngine.VFXModule")] [assembly: InternalsVisibleTo("UnityEngine.VehiclesModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestWWWModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestTextureModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestAudioModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestAssetBundleModule")] [assembly: InternalsVisibleTo("UnityEngine.VirtualTexturingModule")] [assembly: InternalsVisibleTo("UnityEngine.Physics2DModule")] [assembly: InternalsVisibleTo("UnityEngine.PerformanceReportingModule")] [assembly: InternalsVisibleTo("UnityEngine.ParticleSystemModule")] [assembly: InternalsVisibleTo("UnityEngine.AudioModule")] [assembly: InternalsVisibleTo("UnityEngine.AssetBundleModule")] [assembly: InternalsVisibleTo("UnityEngine.HotReloadModule")] [assembly: InternalsVisibleTo("UnityEngine.ARModule")] [assembly: InternalsVisibleTo("UnityEngine.InputModule")] [assembly: InternalsVisibleTo("UnityEngine.JSONSerializeModule")] [assembly: InternalsVisibleTo("UnityEngine.PhysicsModule")] [assembly: InternalsVisibleTo("UnityEngine.ClothModule")] [assembly: InternalsVisibleTo("UnityEngine.AnimationModule")] [assembly: InternalsVisibleTo("UnityEngine.AIModule")] [assembly: InternalsVisibleTo("UnityEngine.AccessibilityModule")] [assembly: InternalsVisibleTo("UnityEngine.CoreModule")] [assembly: InternalsVisibleTo("UnityEngine.SharedInternalsModule")] [assembly: InternalsVisibleTo("UnityEngine")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: InternalsVisibleTo("UnityEngine.AndroidJNIModule")] [assembly: InternalsVisibleTo("UnityEngine.PS5VRModule")] [assembly: InternalsVisibleTo("UnityEngine.ClusterInputModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityConnectModule")] [assembly: InternalsVisibleTo("UnityEngine.NVIDIAModule")] [assembly: InternalsVisibleTo("UnityEngine.LocalizationModule")] [assembly: InternalsVisibleTo("UnityEngine.IMGUIModule")] [assembly: InternalsVisibleTo("UnityEngine.InputLegacyModule")] [assembly: InternalsVisibleTo("UnityEngine.TextRenderingModule")] [assembly: InternalsVisibleTo("UnityEngine.GridModule")] [assembly: InternalsVisibleTo("UnityEngine.GIModule")] [assembly: InternalsVisibleTo("UnityEngine.ClusterRendererModule")] [assembly: InternalsVisibleTo("UnityEngine.GameCenterModule")] [assembly: InternalsVisibleTo("UnityEngine.DSPGraphModule")] [assembly: InternalsVisibleTo("UnityEngine.DirectorModule")] [assembly: InternalsVisibleTo("UnityEngine.CrashReportingModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestModule")] [assembly: InternalsVisibleTo("UnityEngine.TLSModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsCommonModule")] [assembly: InternalsVisibleTo("UnityEngine.ImageConversionModule")] [assembly: InternalsVisibleTo("UnityEngine.Networking")] [assembly: InternalsVisibleTo("UnityEngine.PS5Module")] [assembly: InternalsVisibleTo("UnityEngine.Cloud.Service")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.009")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.008")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.007")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.006")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.005")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.004")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.003")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.002")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.001")] [assembly: InternalsVisibleTo("Unity.Core")] [assembly: InternalsVisibleTo("Unity.Runtime")] [assembly: InternalsVisibleTo("Unity.Collections")] [assembly: InternalsVisibleTo("Unity.Entities.Tests")] [assembly: InternalsVisibleTo("Unity.Entities")] [assembly: InternalsVisibleTo("Unity.Logging")] [assembly: InternalsVisibleTo("Unity.Services.QoS")] [assembly: InternalsVisibleTo("Unity.ucg.QoS")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.010")] [assembly: InternalsVisibleTo("Unity.Networking.Transport")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.011")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.013")] [assembly: InternalsVisibleTo("Unity.Subsystem.Registration")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.005")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.004")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.003")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.002")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.001")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.024")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.023")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.022")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.021")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.020")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.019")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.018")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.017")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.016")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.015")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.014")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.012")] [assembly: InternalsVisibleTo("UnityEngine.Cloud")] [assembly: InternalsVisibleTo("UnityEngine.UI")] [assembly: InternalsVisibleTo("Unity.UIElements.PlayModeTests")] [assembly: InternalsVisibleTo("Unity.UIElements.EditorTests")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.Timeline")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.UnityAnalytics")] [assembly: InternalsVisibleTo("Unity.IntegrationTests")] [assembly: InternalsVisibleTo("Unity.DeploymentTests.Services")] [assembly: InternalsVisibleTo("Unity.Burst.Editor")] [assembly: InternalsVisibleTo("Unity.RuntimeTests")] [assembly: InternalsVisibleTo("Unity.Burst")] [assembly: InternalsVisibleTo("UnityEngine.TestRunner")] [assembly: InternalsVisibleTo("UnityEngine.Purchasing")] [assembly: InternalsVisibleTo("UnityEngine.Advertisements")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsCommon")] [assembly: InternalsVisibleTo("UnityEngine.Analytics")] [assembly: InternalsVisibleTo("Unity.Analytics")] [assembly: InternalsVisibleTo("Unity.Automation")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.Framework")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.Framework")] [assembly: InternalsVisibleTo("Unity.PerformanceTests.RuntimeTestRunner.Tests")] [assembly: InternalsVisibleTo("Unity.UIElements.Editor")] [assembly: InternalsVisibleTo("UnityEngine.UIElementsGameObjectsModule")] [assembly: InternalsVisibleTo("Unity.UIElements")] [assembly: InternalsVisibleTo("Unity.UI.Builder.EditorTests")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.Framework.Tests")] [assembly: InternalsVisibleTo("Unity.UI.Builder.Editor")] [assembly: InternalsVisibleTo("Unity.2D.Sprite.EditorTests")] [assembly: InternalsVisibleTo("UnityEditor.UIBuilderModule")] [assembly: InternalsVisibleTo("Unity.WindowsMRAutomation")] [assembly: InternalsVisibleTo("GoogleAR.UnityNative")] [assembly: InternalsVisibleTo("UnityEngine.SpatialTracking")] [assembly: InternalsVisibleTo("Assembly-CSharp-firstpass-testable")] [assembly: InternalsVisibleTo("Assembly-CSharp-testable")] [assembly: InternalsVisibleTo("Unity.Timeline")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.AllIn1Runner")] [assembly: InternalsVisibleTo("Unity.2D.Sprite.Editor")] [assembly: UnityEngineModuleAssembly] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] namespace UnityEngine.Networking { [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] [NativeConditional("ENABLE_NETWORK && ENABLE_UNET", true)] [NativeHeader("Modules/UNET/UNETConfiguration.h")] [NativeHeader("Modules/UNET/UNetTypes.h")] [NativeHeader("Modules/UNET/UNETManager.h")] public sealed class NetworkTransport { private static int s_nextSceneId = 1; public static bool IsStarted => IsStartedInternal(); public static bool DoesEndPointUsePlatformProtocols(EndPoint endPoint) { if (endPoint.GetType().FullName == "UnityEngine.PS4.SceEndPoint") { SocketAddress socketAddress = endPoint.Serialize(); if (socketAddress[8] != 0 || socketAddress[9] != 0) { return true; } } return false; } public static int ConnectEndPoint(int hostId, EndPoint endPoint, int exceptionConnectionId, out byte error) { error = 0; byte[] array = new byte[4] { 95, 36, 19, 246 }; if (endPoint == null) { throw new NullReferenceException("Null EndPoint provided"); } if (endPoint.GetType().FullName != "UnityEngine.XboxOne.XboxOneEndPoint" && endPoint.GetType().FullName != "UnityEngine.PS4.SceEndPoint" && endPoint.GetType().FullName != "UnityEngine.PSVita.SceEndPoint") { throw new ArgumentException("Endpoint of type XboxOneEndPoint or SceEndPoint required"); } if (endPoint.GetType().FullName == "UnityEngine.XboxOne.XboxOneEndPoint") { if (endPoint.AddressFamily != AddressFamily.InterNetworkV6) { throw new ArgumentException("XboxOneEndPoint has an invalid family"); } SocketAddress socketAddress = endPoint.Serialize(); if (socketAddress.Size != 14) { throw new ArgumentException("XboxOneEndPoint has an invalid size"); } if (socketAddress[0] != 0 || socketAddress[1] != 0) { throw new ArgumentException("XboxOneEndPoint has an invalid family signature"); } if (socketAddress[2] != array[0] || socketAddress[3] != array[1] || socketAddress[4] != array[2] || socketAddress[5] != array[3]) { throw new ArgumentException("XboxOneEndPoint has an invalid signature"); } byte[] array2 = new byte[8]; for (int i = 0; i < array2.Length; i++) { array2[i] = socketAddress[6 + i]; } IntPtr intPtr = new IntPtr(BitConverter.ToInt64(array2, 0)); if (intPtr == IntPtr.Zero) { throw new ArgumentException("XboxOneEndPoint has an invalid SOCKET_STORAGE pointer"); } byte[] array3 = new byte[2]; Marshal.Copy(intPtr, array3, 0, array3.Length); AddressFamily addressFamily = (AddressFamily)((array3[1] << 8) + array3[0]); if (addressFamily != AddressFamily.InterNetworkV6) { throw new ArgumentException("XboxOneEndPoint has corrupt or invalid SOCKET_STORAGE pointer"); } return Internal_ConnectEndPoint(hostId, array2, 128, exceptionConnectionId, out error); } SocketAddress socketAddress2 = endPoint.Serialize(); if (socketAddress2.Size != 16) { throw new ArgumentException("EndPoint has an invalid size"); } if (socketAddress2[0] != socketAddress2.Size) { throw new ArgumentException("EndPoint has an invalid size value"); } if (socketAddress2[1] != 2) { throw new ArgumentException("EndPoint has an invalid family value"); } byte[] array4 = new byte[16]; for (int j = 0; j < array4.Length; j++) { array4[j] = socketAddress2[j]; } return Internal_ConnectEndPoint(hostId, array4, 16, exceptionConnectionId, out error); } private NetworkTransport() { } public static void Init() { InitializeClass(); } public static void Init(GlobalConfig config) { if (config.NetworkEventAvailable != null) { SetNetworkEventAvailableCallback(config.NetworkEventAvailable); } if (config.ConnectionReadyForSend != null) { SetConnectionReadyForSendCallback(config.ConnectionReadyForSend); } InitializeClassWithConfig(new GlobalConfigInternal(config)); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::InitializeClass")] private static extern void InitializeClass(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::InitializeClassWithConfig")] private static extern void InitializeClassWithConfig(GlobalConfigInternal config); public static void Shutdown() { Cleanup(); } [Obsolete("This function has been deprecated. Use AssetDatabase utilities instead.")] public static string GetAssetId(GameObject go) { return ""; } public static void AddSceneId(int id) { if (id > s_nextSceneId) { s_nextSceneId = id + 1; } } public static int GetNextSceneId() { return s_nextSceneId++; } public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, int port, string ip) { if (topology == null) { throw new NullReferenceException("topology is not defined"); } CheckTopology(topology); return AddHostInternal(new HostTopologyInternal(topology), ip, port, minTimeout, maxTimeout); } public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, int port) { return AddHostWithSimulator(topology, minTimeout, maxTimeout, port, null); } public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout) { return AddHostWithSimulator(topology, minTimeout, maxTimeout, 0, null); } public static int AddHost(HostTopology topology, int port, string ip) { return AddHostWithSimulator(topology, 0, 0, port, ip); } public static int AddHost(HostTopology topology, int port) { return AddHost(topology, port, null); } public static int AddHost(HostTopology topology) { return AddHost(topology, 0, null); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->AddHost", ThrowsException = true)] private static extern int AddHostInternal(HostTopologyInternal topologyInt, string ip, int port, int minTimeout, int maxTimeout); public static int AddWebsocketHost(HostTopology topology, int port, string ip) { if (port != 0 && IsPortOpen(ip, port)) { throw new InvalidOperationException("Cannot open web socket on port " + port + " It has been already occupied."); } if (topology == null) { throw new NullReferenceException("topology is not defined"); } CheckTopology(topology); return AddWsHostInternal(new HostTopologyInternal(topology), ip, port); } public static int AddWebsocketHost(HostTopology topology, int port) { return AddWebsocketHost(topology, port, null); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->AddWsHost", ThrowsException = true)] private static extern int AddWsHostInternal(HostTopologyInternal topologyInt, string ip, int port); private static bool IsPortOpen(string ip, int port) { TimeSpan timeout = TimeSpan.FromMilliseconds(500.0); string host = ((ip == null) ? "127.0.0.1" : ip); try { using TcpClient tcpClient = new TcpClient(); IAsyncResult asyncResult = tcpClient.BeginConnect(host, port, null, null); if (!asyncResult.AsyncWaitHandle.WaitOne(timeout)) { return false; } tcpClient.EndConnect(asyncResult); } catch { return false; } return true; } public static void ConnectAsNetworkHost(int hostId, string address, int port, NetworkID network, SourceID source, NodeID node, out byte error) { ConnectAsNetworkHostInternal(hostId, address, port, (ulong)network, (ulong)source, (ushort)node, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->ConnectAsNetworkHost", ThrowsException = true)] private static extern void ConnectAsNetworkHostInternal(int hostId, string address, int port, ulong network, ulong source, ushort node, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->DisconnectNetworkHost", ThrowsException = true)] public static extern void DisconnectNetworkHost(int hostId, out byte error); public static NetworkEventType ReceiveRelayEventFromHost(int hostId, out byte error) { return (NetworkEventType)ReceiveRelayEventFromHostInternal(hostId, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->PopRelayHostData", ThrowsException = true)] private static extern int ReceiveRelayEventFromHostInternal(int hostId, out byte error); public static int ConnectToNetworkPeer(int hostId, string address, int port, int exceptionConnectionId, int relaySlotId, NetworkID network, SourceID source, NodeID node, int bytesPerSec, float bucketSizeFactor, out byte error) { return ConnectToNetworkPeerInternal(hostId, address, port, exceptionConnectionId, relaySlotId, (ulong)network, (ulong)source, (ushort)node, bytesPerSec, bucketSizeFactor, out error); } public static int ConnectToNetworkPeer(int hostId, string address, int port, int exceptionConnectionId, int relaySlotId, NetworkID network, SourceID source, NodeID node, out byte error) { return ConnectToNetworkPeer(hostId, address, port, exceptionConnectionId, relaySlotId, network, source, node, 0, 0f, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->ConnectToNetworkPeer", ThrowsException = true)] private static extern int ConnectToNetworkPeerInternal(int hostId, string address, int port, int exceptionConnectionId, int relaySlotId, ulong network, ulong source, ushort node, int bytesPerSec, float bucketSizeFactor, out byte error); [Obsolete("GetCurrentIncomingMessageAmount has been deprecated.")] public static int GetCurrentIncomingMessageAmount() { return 0; } [Obsolete("GetCurrentOutgoingMessageAmount has been deprecated.")] public static int GetCurrentOutgoingMessageAmount() { return 0; } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetIncomingMessageQueueSize", ThrowsException = true)] public static extern int GetIncomingMessageQueueSize(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingMessageQueueSize", ThrowsException = true)] public static extern int GetOutgoingMessageQueueSize(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetCurrentRTT", ThrowsException = true)] public static extern int GetCurrentRTT(int hostId, int connectionId, out byte error); [Obsolete("GetCurrentRtt() has been deprecated.")] public static int GetCurrentRtt(int hostId, int connectionId, out byte error) { return GetCurrentRTT(hostId, connectionId, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetIncomingPacketLossCount", ThrowsException = true)] public static extern int GetIncomingPacketLossCount(int hostId, int connectionId, out byte error); [Obsolete("GetNetworkLostPacketNum() has been deprecated.")] public static int GetNetworkLostPacketNum(int hostId, int connectionId, out byte error) { return GetIncomingPacketLossCount(hostId, connectionId, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetIncomingPacketCount", ThrowsException = true)] public static extern int GetIncomingPacketCount(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingPacketNetworkLossPercent", ThrowsException = true)] public static extern int GetOutgoingPacketNetworkLossPercent(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingPacketOverflowLossPercent", ThrowsException = true)] public static extern int GetOutgoingPacketOverflowLossPercent(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetMaxAllowedBandwidth", ThrowsException = true)] public static extern int GetMaxAllowedBandwidth(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetAckBufferCount", ThrowsException = true)] public static extern int GetAckBufferCount(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetIncomingPacketDropCountForAllHosts", ThrowsException = true)] public static extern int GetIncomingPacketDropCountForAllHosts(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetIncomingPacketCountForAllHosts", ThrowsException = true)] public static extern int GetIncomingPacketCountForAllHosts(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingPacketCount", ThrowsException = true)] public static extern int GetOutgoingPacketCount(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingPacketCount", ThrowsException = true)] public static extern int GetOutgoingPacketCountForHost(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingPacketCount", ThrowsException = true)] public static extern int GetOutgoingPacketCountForConnection(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingMessageCount", ThrowsException = true)] public static extern int GetOutgoingMessageCount(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingMessageCount", ThrowsException = true)] public static extern int GetOutgoingMessageCountForHost(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingMessageCount", ThrowsException = true)] public static extern int GetOutgoingMessageCountForConnection(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingUserBytesCount", ThrowsException = true)] public static extern int GetOutgoingUserBytesCount(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingUserBytesCount", ThrowsException = true)] public static extern int GetOutgoingUserBytesCountForHost(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingUserBytesCount", ThrowsException = true)] public static extern int GetOutgoingUserBytesCountForConnection(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingSystemBytesCount", ThrowsException = true)] public static extern int GetOutgoingSystemBytesCount(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingSystemBytesCount", ThrowsException = true)] public static extern int GetOutgoingSystemBytesCountForHost(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingSystemBytesCount", ThrowsException = true)] public static extern int GetOutgoingSystemBytesCountForConnection(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingFullBytesCount", ThrowsException = true)] public static extern int GetOutgoingFullBytesCount(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingFullBytesCount", ThrowsException = true)] public static extern int GetOutgoingFullBytesCountForHost(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetOutgoingFullBytesCount", ThrowsException = true)] public static extern int GetOutgoingFullBytesCountForConnection(int hostId, int connectionId, out byte error); [Obsolete("GetPacketSentRate has been deprecated.")] public static int GetPacketSentRate(int hostId, int connectionId, out byte error) { error = 0; return 0; } [Obsolete("GetPacketReceivedRate has been deprecated.")] public static int GetPacketReceivedRate(int hostId, int connectionId, out byte error) { error = 0; return 0; } [Obsolete("GetRemotePacketReceivedRate has been deprecated.")] public static int GetRemotePacketReceivedRate(int hostId, int connectionId, out byte error) { error = 0; return 0; } [Obsolete("GetNetIOTimeuS has been deprecated.")] public static int GetNetIOTimeuS() { return 0; } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetConnectionInfo", ThrowsException = true)] public static extern string GetConnectionInfo(int hostId, int connectionId, out int port, out ulong network, out ushort dstNode, out byte error); public static void GetConnectionInfo(int hostId, int connectionId, out string address, out int port, out NetworkID network, out NodeID dstNode, out byte error) { address = GetConnectionInfo(hostId, connectionId, out port, out var network2, out var dstNode2, out error); network = (NetworkID)network2; dstNode = (NodeID)dstNode2; } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetNetworkTimestamp", ThrowsException = true)] public static extern int GetNetworkTimestamp(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetRemoteDelayTimeMS", ThrowsException = true)] public static extern int GetRemoteDelayTimeMS(int hostId, int connectionId, int remoteTime, out byte error); public static bool StartSendMulticast(int hostId, int channelId, byte[] buffer, int size, out byte error) { return StartSendMulticastInternal(hostId, channelId, buffer, size, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->StartSendMulticast", ThrowsException = true)] private static extern bool StartSendMulticastInternal(int hostId, int channelId, [Out] byte[] buffer, int size, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->SendMulticast", ThrowsException = true)] public static extern bool SendMulticast(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->FinishSendMulticast", ThrowsException = true)] public static extern bool FinishSendMulticast(int hostId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetMaxPacketSize", ThrowsException = true)] private static extern int GetMaxPacketSize(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->RemoveHost", ThrowsException = true)] public static extern bool RemoveHost(int hostId); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::IsStarted")] private static extern bool IsStartedInternal(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->Connect", ThrowsException = true)] public static extern int Connect(int hostId, string address, int port, int exeptionConnectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->ConnectWithSimulator", ThrowsException = true)] private static extern int ConnectWithSimulatorInternal(int hostId, string address, int port, int exeptionConnectionId, out byte error, ConnectionSimulatorConfigInternal conf); public static int ConnectWithSimulator(int hostId, string address, int port, int exeptionConnectionId, out byte error, ConnectionSimulatorConfig conf) { return ConnectWithSimulatorInternal(hostId, address, port, exeptionConnectionId, out error, new ConnectionSimulatorConfigInternal(conf)); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->Disconnect", ThrowsException = true)] public static extern bool Disconnect(int hostId, int connectionId, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->ConnectSockAddr", ThrowsException = true)] private static extern int Internal_ConnectEndPoint(int hostId, [Out] byte[] sockAddrStorage, int sockAddrStorageLen, int exceptionConnectionId, out byte error); public static bool Send(int hostId, int connectionId, int channelId, byte[] buffer, int size, out byte error) { if (buffer == null) { throw new NullReferenceException("send buffer is not initialized"); } return SendWrapper(hostId, connectionId, channelId, buffer, size, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->Send", ThrowsException = true)] private static extern bool SendWrapper(int hostId, int connectionId, int channelId, [Out] byte[] buffer, int size, out byte error); public static bool QueueMessageForSending(int hostId, int connectionId, int channelId, byte[] buffer, int size, out byte error) { if (buffer == null) { throw new NullReferenceException("send buffer is not initialized"); } return QueueMessageForSendingWrapper(hostId, connectionId, channelId, buffer, size, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->QueueMessageForSending", ThrowsException = true)] private static extern bool QueueMessageForSendingWrapper(int hostId, int connectionId, int channelId, [Out] byte[] buffer, int size, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->SendQueuedMessages", ThrowsException = true)] public static extern bool SendQueuedMessages(int hostId, int connectionId, out byte error); public static NetworkEventType Receive(out int hostId, out int connectionId, out int channelId, byte[] buffer, int bufferSize, out int receivedSize, out byte error) { return (NetworkEventType)PopData(out hostId, out connectionId, out channelId, buffer, bufferSize, out receivedSize, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->PopData", ThrowsException = true)] private static extern int PopData(out int hostId, out int connectionId, out int channelId, [Out] byte[] buffer, int bufferSize, out int receivedSize, out byte error); public static NetworkEventType ReceiveFromHost(int hostId, out int connectionId, out int channelId, byte[] buffer, int bufferSize, out int receivedSize, out byte error) { return (NetworkEventType)PopDataFromHost(hostId, out connectionId, out channelId, buffer, bufferSize, out receivedSize, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->PopDataFromHost", ThrowsException = true)] private static extern int PopDataFromHost(int hostId, out int connectionId, out int channelId, [Out] byte[] buffer, int bufferSize, out int receivedSize, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->SetPacketStat", ThrowsException = true)] public static extern void SetPacketStat(int direction, int packetStatId, int numMsgs, int numBytes); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::SetNetworkEventAvailableCallback")] [NativeThrows] private static extern void SetNetworkEventAvailableCallback(Action callback); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Cleanup")] private static extern void Cleanup(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::SetConnectionReadyForSendCallback")] [NativeThrows] private static extern void SetConnectionReadyForSendCallback(Action callback); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->NotifyWhenConnectionReadyForSend", ThrowsException = true)] public static extern bool NotifyWhenConnectionReadyForSend(int hostId, int connectionId, int notificationLevel, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetHostPort", ThrowsException = true)] public static extern int GetHostPort(int hostId); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->StartBroadcastDiscoveryWithData", ThrowsException = true)] private static extern bool StartBroadcastDiscoveryWithData(int hostId, int broadcastPort, int key, int version, int subversion, [Out] byte[] buffer, int size, int timeout, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->StartBroadcastDiscoveryWithoutData", ThrowsException = true)] private static extern bool StartBroadcastDiscoveryWithoutData(int hostId, int broadcastPort, int key, int version, int subversion, int timeout, out byte error); public static bool StartBroadcastDiscovery(int hostId, int broadcastPort, int key, int version, int subversion, byte[] buffer, int size, int timeout, out byte error) { if (buffer != null) { if (buffer.Length < size) { throw new ArgumentOutOfRangeException("Size: " + size + " > buffer.Length " + buffer.Length); } if (size == 0) { throw new ArgumentOutOfRangeException("Size is zero while buffer exists, please pass null and 0 as buffer and size parameters"); } } if (buffer == null) { return StartBroadcastDiscoveryWithoutData(hostId, broadcastPort, key, version, subversion, timeout, out error); } return StartBroadcastDiscoveryWithData(hostId, broadcastPort, key, version, subversion, buffer, size, timeout, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->StopBroadcastDiscovery", ThrowsException = true)] public static extern void StopBroadcastDiscovery(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->IsBroadcastDiscoveryRunning", ThrowsException = true)] public static extern bool IsBroadcastDiscoveryRunning(); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->SetBroadcastCredentials", ThrowsException = true)] public static extern void SetBroadcastCredentials(int hostId, int key, int version, int subversion, out byte error); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetBroadcastConnectionInfoInternal", ThrowsException = true)] public static extern string GetBroadcastConnectionInfo(int hostId, out int port, out byte error); public static void GetBroadcastConnectionInfo(int hostId, out string address, out int port, out byte error) { address = GetBroadcastConnectionInfo(hostId, out port, out error); } public static void GetBroadcastConnectionMessage(int hostId, byte[] buffer, int bufferSize, out int receivedSize, out byte error) { GetBroadcastConnectionMessageInternal(hostId, buffer, bufferSize, out receivedSize, out error); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::SetMulticastLock")] public static extern void SetMulticastLock(bool enabled); [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetBroadcastConnectionMessage", ThrowsException = true)] private static extern void GetBroadcastConnectionMessageInternal(int hostId, [Out] byte[] buffer, int bufferSize, out int receivedSize, out byte error); private static void CheckTopology(HostTopology topology) { int maxPacketSize = GetMaxPacketSize(); if (topology.DefaultConfig.PacketSize > maxPacketSize) { throw new ArgumentOutOfRangeException("Default config: packet size should be less than packet size defined in global config: " + maxPacketSize); } for (int i = 0; i < topology.SpecialConnectionConfigs.Count; i++) { if (topology.SpecialConnectionConfigs[i].PacketSize > maxPacketSize) { throw new ArgumentOutOfRangeException("Special config " + i + ": packet size should be less than packet size defined in global config: " + maxPacketSize); } } } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->LoadEncryptionLibrary", ThrowsException = true)] private static extern bool LoadEncryptionLibraryInternal(string libraryName); public static bool LoadEncryptionLibrary(string libraryName) { return LoadEncryptionLibraryInternal(libraryName); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->UnloadEncryptionLibrary", ThrowsException = true)] private static extern void UnloadEncryptionLibraryInternal(); public static void UnloadEncryptionLibrary() { UnloadEncryptionLibraryInternal(); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->IsEncryptionActive", ThrowsException = true)] private static extern bool IsEncryptionActiveInternal(); public static bool IsEncryptionActive() { return IsEncryptionActiveInternal(); } [MethodImpl(MethodImplOptions.InternalCall)] [FreeFunction("UNETManager::Get()->GetEncryptionSafeMaxPacketSize", ThrowsException = true)] private static extern short GetEncryptionSafeMaxPacketSizeInternal(short maxPacketSize); public static short GetEncryptionSafeMaxPacketSize(short maxPacketSize) { return GetEncryptionSafeMaxPacketSizeInternal(maxPacketSize); } } public enum NetworkEventType { DataEvent, ConnectEvent, DisconnectEvent, Nothing, BroadcastEvent } public enum QosType { Unreliable, UnreliableFragmented, UnreliableSequenced, Reliable, ReliableFragmented, ReliableSequenced, StateUpdate, ReliableStateUpdate, AllCostDelivery, UnreliableFragmentedSequenced, ReliableFragmentedSequenced } public enum NetworkError { Ok, WrongHost, WrongConnection, WrongChannel, NoResources, BadMessage, Timeout, MessageToLong, WrongOperation, VersionMismatch, CRCMismatch, DNSFailure, UsageError } public enum ReactorModel { SelectReactor, FixRateReactor } public enum ConnectionAcksType { Acks32 = 1, Acks64, Acks96, Acks128 } [Serializable] [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] public class ChannelQOS { [SerializeField] internal QosType m_Type; [SerializeField] internal bool m_BelongsSharedOrderChannel; public QosType QOS => m_Type; public bool BelongsToSharedOrderChannel => m_BelongsSharedOrderChannel; public ChannelQOS(QosType value) { m_Type = value; m_BelongsSharedOrderChannel = false; } public ChannelQOS() { m_Type = QosType.Unreliable; m_BelongsSharedOrderChannel = false; } public ChannelQOS(ChannelQOS channel) { if (channel == null) { throw new NullReferenceException("channel is not defined"); } m_Type = channel.m_Type; m_BelongsSharedOrderChannel = channel.m_BelongsSharedOrderChannel; } } [Serializable] [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] public class ConnectionConfig { private const int g_MinPacketSize = 128; [SerializeField] private ushort m_PacketSize; [SerializeField] private ushort m_FragmentSize; [SerializeField] private uint m_ResendTimeout; [SerializeField] private uint m_DisconnectTimeout; [SerializeField] private uint m_ConnectTimeout; [SerializeField] private uint m_MinUpdateTimeout; [SerializeField] private uint m_PingTimeout; [SerializeField] private uint m_ReducedPingTimeout; [SerializeField] private uint m_AllCostTimeout; [SerializeField] private byte m_NetworkDropThreshold; [SerializeField] private byte m_OverflowDropThreshold; [SerializeField] private byte m_MaxConnectionAttempt; [SerializeField] private uint m_AckDelay; [SerializeField] private uint m_SendDelay; [SerializeField] private ushort m_MaxCombinedReliableMessageSize; [SerializeField] private ushort m_MaxCombinedReliableMessageCount; [SerializeField] private ushort m_MaxSentMessageQueueSize; [SerializeField] private ConnectionAcksType m_AcksType; [SerializeField] private bool m_UsePlatformSpecificProtocols; [SerializeField] private uint m_InitialBandwidth; [SerializeField] private float m_BandwidthPeakFactor; [SerializeField] private ushort m_WebSocketReceiveBufferMaxSize; [SerializeField] private uint m_UdpSocketReceiveBufferMaxSize; [SerializeField] private string m_SSLCertFilePath; [SerializeField] private string m_SSLPrivateKeyFilePath; [SerializeField] private string m_SSLCAFilePath; [SerializeField] internal List m_Channels = new List(); [SerializeField] internal List> m_SharedOrderChannels = new List>(); public ushort PacketSize { get { return m_PacketSize; } set { m_PacketSize = value; } } public ushort FragmentSize { get { return m_FragmentSize; } set { m_FragmentSize = value; } } public uint ResendTimeout { get { return m_ResendTimeout; } set { m_ResendTimeout = value; } } public uint DisconnectTimeout { get { return m_DisconnectTimeout; } set { m_DisconnectTimeout = value; } } public uint ConnectTimeout { get { return m_ConnectTimeout; } set { m_ConnectTimeout = value; } } public uint MinUpdateTimeout { get { return m_MinUpdateTimeout; } set { if (value == 0) { throw new ArgumentOutOfRangeException("Minimal update timeout should be > 0"); } m_MinUpdateTimeout = value; } } public uint PingTimeout { get { return m_PingTimeout; } set { m_PingTimeout = value; } } public uint ReducedPingTimeout { get { return m_ReducedPingTimeout; } set { m_ReducedPingTimeout = value; } } public uint AllCostTimeout { get { return m_AllCostTimeout; } set { m_AllCostTimeout = value; } } public byte NetworkDropThreshold { get { return m_NetworkDropThreshold; } set { m_NetworkDropThreshold = value; } } public byte OverflowDropThreshold { get { return m_OverflowDropThreshold; } set { m_OverflowDropThreshold = value; } } public byte MaxConnectionAttempt { get { return m_MaxConnectionAttempt; } set { m_MaxConnectionAttempt = value; } } public uint AckDelay { get { return m_AckDelay; } set { m_AckDelay = value; } } public uint SendDelay { get { return m_SendDelay; } set { m_SendDelay = value; } } public ushort MaxCombinedReliableMessageSize { get { return m_MaxCombinedReliableMessageSize; } set { m_MaxCombinedReliableMessageSize = value; } } public ushort MaxCombinedReliableMessageCount { get { return m_MaxCombinedReliableMessageCount; } set { m_MaxCombinedReliableMessageCount = value; } } public ushort MaxSentMessageQueueSize { get { return m_MaxSentMessageQueueSize; } set { m_MaxSentMessageQueueSize = value; } } public ConnectionAcksType AcksType { get { return m_AcksType; } set { m_AcksType = value; } } [Obsolete("IsAcksLong is deprecated. Use AcksType = ConnectionAcksType.Acks64", false)] public bool IsAcksLong { get { return m_AcksType != ConnectionAcksType.Acks32; } set { if (value && m_AcksType == ConnectionAcksType.Acks32) { m_AcksType = ConnectionAcksType.Acks64; } else if (!value) { m_AcksType = ConnectionAcksType.Acks32; } } } public bool UsePlatformSpecificProtocols { get { return m_UsePlatformSpecificProtocols; } set { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 if (value && (int)Application.platform != 25) { throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); } m_UsePlatformSpecificProtocols = value; } } public uint InitialBandwidth { get { return m_InitialBandwidth; } set { m_InitialBandwidth = value; } } public float BandwidthPeakFactor { get { return m_BandwidthPeakFactor; } set { m_BandwidthPeakFactor = value; } } public ushort WebSocketReceiveBufferMaxSize { get { return m_WebSocketReceiveBufferMaxSize; } set { m_WebSocketReceiveBufferMaxSize = value; } } public uint UdpSocketReceiveBufferMaxSize { get { return m_UdpSocketReceiveBufferMaxSize; } set { m_UdpSocketReceiveBufferMaxSize = value; } } public string SSLCertFilePath { get { return m_SSLCertFilePath; } set { m_SSLCertFilePath = value; } } public string SSLPrivateKeyFilePath { get { return m_SSLPrivateKeyFilePath; } set { m_SSLPrivateKeyFilePath = value; } } public string SSLCAFilePath { get { return m_SSLCAFilePath; } set { m_SSLCAFilePath = value; } } public int ChannelCount => m_Channels.Count; public int SharedOrderChannelCount => m_SharedOrderChannels.Count; public List Channels => m_Channels; public ConnectionConfig() { m_PacketSize = 1440; m_FragmentSize = 500; m_ResendTimeout = 1200u; m_DisconnectTimeout = 2000u; m_ConnectTimeout = 2000u; m_MinUpdateTimeout = 10u; m_PingTimeout = 500u; m_ReducedPingTimeout = 100u; m_AllCostTimeout = 20u; m_NetworkDropThreshold = 5; m_OverflowDropThreshold = 5; m_MaxConnectionAttempt = 10; m_AckDelay = 33u; m_SendDelay = 10u; m_MaxCombinedReliableMessageSize = 100; m_MaxCombinedReliableMessageCount = 10; m_MaxSentMessageQueueSize = 512; m_AcksType = ConnectionAcksType.Acks32; m_UsePlatformSpecificProtocols = false; m_InitialBandwidth = 0u; m_BandwidthPeakFactor = 2f; m_WebSocketReceiveBufferMaxSize = 0; m_UdpSocketReceiveBufferMaxSize = 0u; m_SSLCertFilePath = null; m_SSLPrivateKeyFilePath = null; m_SSLCAFilePath = null; } public ConnectionConfig(ConnectionConfig config) { if (config == null) { throw new NullReferenceException("config is not defined"); } m_PacketSize = config.m_PacketSize; m_FragmentSize = config.m_FragmentSize; m_ResendTimeout = config.m_ResendTimeout; m_DisconnectTimeout = config.m_DisconnectTimeout; m_ConnectTimeout = config.m_ConnectTimeout; m_MinUpdateTimeout = config.m_MinUpdateTimeout; m_PingTimeout = config.m_PingTimeout; m_ReducedPingTimeout = config.m_ReducedPingTimeout; m_AllCostTimeout = config.m_AllCostTimeout; m_NetworkDropThreshold = config.m_NetworkDropThreshold; m_OverflowDropThreshold = config.m_OverflowDropThreshold; m_MaxConnectionAttempt = config.m_MaxConnectionAttempt; m_AckDelay = config.m_AckDelay; m_SendDelay = config.m_SendDelay; m_MaxCombinedReliableMessageSize = config.MaxCombinedReliableMessageSize; m_MaxCombinedReliableMessageCount = config.m_MaxCombinedReliableMessageCount; m_MaxSentMessageQueueSize = config.m_MaxSentMessageQueueSize; m_AcksType = config.m_AcksType; m_UsePlatformSpecificProtocols = config.m_UsePlatformSpecificProtocols; m_InitialBandwidth = config.m_InitialBandwidth; if (m_InitialBandwidth == 0) { m_InitialBandwidth = (uint)(m_PacketSize * 1000) / m_MinUpdateTimeout; } m_BandwidthPeakFactor = config.m_BandwidthPeakFactor; m_WebSocketReceiveBufferMaxSize = config.m_WebSocketReceiveBufferMaxSize; m_UdpSocketReceiveBufferMaxSize = config.m_UdpSocketReceiveBufferMaxSize; m_SSLCertFilePath = config.m_SSLCertFilePath; m_SSLPrivateKeyFilePath = config.m_SSLPrivateKeyFilePath; m_SSLCAFilePath = config.m_SSLCAFilePath; foreach (ChannelQOS channel in config.m_Channels) { m_Channels.Add(new ChannelQOS(channel)); } foreach (List sharedOrderChannel in config.m_SharedOrderChannels) { m_SharedOrderChannels.Add(sharedOrderChannel); } } public static void Validate(ConnectionConfig config) { if (config.m_PacketSize < 128) { throw new ArgumentOutOfRangeException("PacketSize should be > " + 128); } if (config.m_FragmentSize >= config.m_PacketSize - 128) { throw new ArgumentOutOfRangeException("FragmentSize should be < PacketSize - " + 128); } if (config.m_Channels.Count > 255) { throw new ArgumentOutOfRangeException("Channels number should be less than 256"); } } public byte AddChannel(QosType value) { if (m_Channels.Count > 255) { throw new ArgumentOutOfRangeException("Channels Count should be less than 256"); } if (!Enum.IsDefined(typeof(QosType), value)) { int num = (int)value; throw new ArgumentOutOfRangeException("requested qos type doesn't exist: " + num); } ChannelQOS item = new ChannelQOS(value); m_Channels.Add(item); return (byte)(m_Channels.Count - 1); } public void MakeChannelsSharedOrder(List channelIndices) { if (channelIndices == null) { throw new NullReferenceException("channelIndices must not be null"); } if (channelIndices.Count == 0) { throw new ArgumentOutOfRangeException("Received empty list of shared order channel indexes"); } for (byte b = 0; b < channelIndices.Count; b++) { byte b2 = channelIndices[b]; if (b2 >= m_Channels.Count) { throw new ArgumentOutOfRangeException("Shared order channel list contains wrong channel index " + b2); } ChannelQOS channelQOS = m_Channels[b2]; if (channelQOS.BelongsToSharedOrderChannel) { throw new ArgumentException("Channel with index " + b2 + " has been already included to other shared order channel"); } if (channelQOS.QOS != QosType.Reliable && channelQOS.QOS != QosType.Unreliable) { throw new ArgumentException("Only Reliable and Unreliable QoS are allowed for shared order channel, wrong channel is with index " + b2); } } for (byte b3 = 0; b3 < channelIndices.Count; b3++) { byte index = channelIndices[b3]; m_Channels[index].m_BelongsSharedOrderChannel = true; } List item = new List(channelIndices); m_SharedOrderChannels.Add(item); } public QosType GetChannel(byte idx) { if (idx >= m_Channels.Count) { throw new ArgumentOutOfRangeException("requested index greater than maximum channels count"); } return m_Channels[idx].QOS; } public IList GetSharedOrderChannels(byte idx) { if (idx >= m_SharedOrderChannels.Count) { throw new ArgumentOutOfRangeException("requested index greater than maximum shared order channels count"); } return m_SharedOrderChannels[idx].AsReadOnly(); } } [Serializable] [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] public class HostTopology { [SerializeField] private ConnectionConfig m_DefConfig = null; [SerializeField] private int m_MaxDefConnections = 0; [SerializeField] private List m_SpecialConnections = new List(); [SerializeField] private ushort m_ReceivedMessagePoolSize = 1024; [SerializeField] private ushort m_SentMessagePoolSize = 1024; [SerializeField] private float m_MessagePoolSizeGrowthFactor = 0.75f; public ConnectionConfig DefaultConfig => m_DefConfig; public int MaxDefaultConnections => m_MaxDefConnections; public int SpecialConnectionConfigsCount => m_SpecialConnections.Count; public List SpecialConnectionConfigs => m_SpecialConnections; public ushort ReceivedMessagePoolSize { get { return m_ReceivedMessagePoolSize; } set { m_ReceivedMessagePoolSize = value; } } public ushort SentMessagePoolSize { get { return m_SentMessagePoolSize; } set { m_SentMessagePoolSize = value; } } public float MessagePoolSizeGrowthFactor { get { return m_MessagePoolSizeGrowthFactor; } set { if ((double)value <= 0.5 || (double)value > 1.0) { throw new ArgumentException("pool growth factor should be varied between 0.5 and 1.0"); } m_MessagePoolSizeGrowthFactor = value; } } public HostTopology(ConnectionConfig defaultConfig, int maxDefaultConnections) { if (defaultConfig == null) { throw new NullReferenceException("config is not defined"); } if (maxDefaultConnections <= 0) { throw new ArgumentOutOfRangeException("maxConnections", "Number of connections should be > 0"); } if (maxDefaultConnections >= 65535) { throw new ArgumentOutOfRangeException("maxConnections", "Number of connections should be < 65535"); } ConnectionConfig.Validate(defaultConfig); m_DefConfig = new ConnectionConfig(defaultConfig); m_MaxDefConnections = maxDefaultConnections; } private HostTopology() { } public ConnectionConfig GetSpecialConnectionConfig(int i) { if (i > m_SpecialConnections.Count || i == 0) { throw new ArgumentException("special configuration index is out of valid range"); } return m_SpecialConnections[i - 1]; } public int AddSpecialConnectionConfig(ConnectionConfig config) { if (m_MaxDefConnections + m_SpecialConnections.Count + 1 >= 65535) { throw new ArgumentOutOfRangeException("maxConnections", "Number of connections should be < 65535"); } m_SpecialConnections.Add(new ConnectionConfig(config)); return m_SpecialConnections.Count; } } [Serializable] [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] public class GlobalConfig { private const uint g_MaxTimerTimeout = 12000u; private const uint g_MaxNetSimulatorTimeout = 12000u; private const ushort g_MaxHosts = 128; [SerializeField] private uint m_ThreadAwakeTimeout; [SerializeField] private ReactorModel m_ReactorModel; [SerializeField] private ushort m_ReactorMaximumReceivedMessages; [SerializeField] private ushort m_ReactorMaximumSentMessages; [SerializeField] private ushort m_MaxPacketSize; [SerializeField] private ushort m_MaxHosts; [SerializeField] private byte m_ThreadPoolSize; [SerializeField] private uint m_MinTimerTimeout; [SerializeField] private uint m_MaxTimerTimeout; [SerializeField] private uint m_MinNetSimulatorTimeout; [SerializeField] private uint m_MaxNetSimulatorTimeout; [SerializeField] private Action m_ConnectionReadyForSend; [SerializeField] private Action m_NetworkEventAvailable; public uint ThreadAwakeTimeout { get { return m_ThreadAwakeTimeout; } set { if (value == 0) { throw new ArgumentOutOfRangeException("Minimal thread awake timeout should be > 0"); } m_ThreadAwakeTimeout = value; } } public ReactorModel ReactorModel { get { return m_ReactorModel; } set { m_ReactorModel = value; } } public ushort ReactorMaximumReceivedMessages { get { return m_ReactorMaximumReceivedMessages; } set { m_ReactorMaximumReceivedMessages = value; } } public ushort ReactorMaximumSentMessages { get { return m_ReactorMaximumSentMessages; } set { m_ReactorMaximumSentMessages = value; } } public ushort MaxPacketSize { get { return m_MaxPacketSize; } set { m_MaxPacketSize = value; } } public ushort MaxHosts { get { return m_MaxHosts; } set { if (value == 0) { throw new ArgumentOutOfRangeException("MaxHosts", "Maximum hosts number should be > 0"); } if (value > 128) { throw new ArgumentOutOfRangeException("MaxHosts", "Maximum hosts number should be <= " + (ushort)128); } m_MaxHosts = value; } } public byte ThreadPoolSize { get { return m_ThreadPoolSize; } set { m_ThreadPoolSize = value; } } public uint MinTimerTimeout { get { return m_MinTimerTimeout; } set { if (value > MaxTimerTimeout) { throw new ArgumentOutOfRangeException("MinTimerTimeout should be < MaxTimerTimeout"); } if (value == 0) { throw new ArgumentOutOfRangeException("MinTimerTimeout should be > 0"); } m_MinTimerTimeout = value; } } public uint MaxTimerTimeout { get { return m_MaxTimerTimeout; } set { if (value == 0) { throw new ArgumentOutOfRangeException("MaxTimerTimeout should be > 0"); } if (value > 12000) { throw new ArgumentOutOfRangeException("MaxTimerTimeout should be <=" + 12000u); } m_MaxTimerTimeout = value; } } public uint MinNetSimulatorTimeout { get { return m_MinNetSimulatorTimeout; } set { if (value > MaxNetSimulatorTimeout) { throw new ArgumentOutOfRangeException("MinNetSimulatorTimeout should be < MaxTimerTimeout"); } if (value == 0) { throw new ArgumentOutOfRangeException("MinNetSimulatorTimeout should be > 0"); } m_MinNetSimulatorTimeout = value; } } public uint MaxNetSimulatorTimeout { get { return m_MaxNetSimulatorTimeout; } set { if (value == 0) { throw new ArgumentOutOfRangeException("MaxNetSimulatorTimeout should be > 0"); } if (value > 12000) { throw new ArgumentOutOfRangeException("MaxNetSimulatorTimeout should be <=" + 12000u); } m_MaxNetSimulatorTimeout = value; } } public Action NetworkEventAvailable { get { return m_NetworkEventAvailable; } set { m_NetworkEventAvailable = value; } } public Action ConnectionReadyForSend { get { return m_ConnectionReadyForSend; } set { m_ConnectionReadyForSend = value; } } public GlobalConfig() { m_ThreadAwakeTimeout = 1u; m_ReactorModel = ReactorModel.SelectReactor; m_ReactorMaximumReceivedMessages = 1024; m_ReactorMaximumSentMessages = 1024; m_MaxPacketSize = 2000; m_MaxHosts = 16; m_ThreadPoolSize = 1; m_MinTimerTimeout = 1u; m_MaxTimerTimeout = 12000u; m_MinNetSimulatorTimeout = 1u; m_MaxNetSimulatorTimeout = 12000u; m_ConnectionReadyForSend = null; m_NetworkEventAvailable = null; } } [Obsolete("The UNET transport will be removed in the future as soon a replacement is ready.")] public class ConnectionSimulatorConfig : IDisposable { internal int m_OutMinDelay; internal int m_OutAvgDelay; internal int m_InMinDelay; internal int m_InAvgDelay; internal float m_PacketLossPercentage; public ConnectionSimulatorConfig(int outMinDelay, int outAvgDelay, int inMinDelay, int inAvgDelay, float packetLossPercentage) { m_OutMinDelay = outMinDelay; m_OutAvgDelay = outAvgDelay; m_InMinDelay = inMinDelay; m_InAvgDelay = inAvgDelay; m_PacketLossPercentage = packetLossPercentage; } [ThreadAndSerializationSafe] public void Dispose() { } ~ConnectionSimulatorConfig() { Dispose(); } } public class Utility { private static Dictionary s_dictTokens = new Dictionary(); [Obsolete("This property is unused and should not be referenced in code.", true)] public static bool useRandomSourceID { get { return false; } set { } } private Utility() { } public static SourceID GetSourceID() { return (SourceID)SystemInfo.deviceUniqueIdentifier.GetHashCode(); } [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This function is unused and should not be referenced in code. Please sign in and setup your project in the editor instead.", true)] public static void SetAppID(AppID newAppID) { } [Obsolete("This function is unused and should not be referenced in code. Please sign in and setup your project in the editor instead.", true)] [EditorBrowsable(EditorBrowsableState.Never)] public static AppID GetAppID() { return AppID.Invalid; } public static void SetAccessTokenForNetwork(NetworkID netId, NetworkAccessToken accessToken) { if (s_dictTokens.ContainsKey(netId)) { s_dictTokens.Remove(netId); } s_dictTokens.Add(netId, accessToken); } public static NetworkAccessToken GetAccessTokenForNetwork(NetworkID netId) { if (!s_dictTokens.TryGetValue(netId, out var value)) { return new NetworkAccessToken(); } return value; } } [StructLayout(LayoutKind.Sequential)] [NativeConditional("ENABLE_NETWORK && ENABLE_UNET", true)] [NativeHeader("Modules/UNET/UNETConfiguration.h")] [NativeHeader("Modules/UNET/UNetTypes.h")] [NativeHeader("Modules/UNET/UNETManager.h")] internal class ConnectionConfigInternal : IDisposable { public IntPtr m_Ptr; [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort FragmentSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint ResendTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint DisconnectTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint ConnectTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint MinUpdateTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint PingTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint ReducedPingTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint AllCostTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte NetworkDropThreshold { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte OverflowDropThreshold { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte MaxConnectionAttempt { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint AckDelay { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint SendDelay { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort MaxCombinedReliableMessageSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort MaxCombinedReliableMessageCount { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort MaxSentMessageQueueSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte AcksType { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern bool UsePlatformSpecificProtocols { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint InitialBandwidth { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern float BandwidthPeakFactor { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort WebSocketReceiveBufferMaxSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint UdpSocketReceiveBufferMaxSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } public ConnectionConfigInternal(ConnectionConfig config) { if (config == null) { throw new NullReferenceException("config is not defined"); } m_Ptr = InternalCreate(); if (!SetPacketSize(config.PacketSize)) { throw new ArgumentOutOfRangeException("PacketSize is too small"); } FragmentSize = config.FragmentSize; ResendTimeout = config.ResendTimeout; DisconnectTimeout = config.DisconnectTimeout; ConnectTimeout = config.ConnectTimeout; MinUpdateTimeout = config.MinUpdateTimeout; PingTimeout = config.PingTimeout; ReducedPingTimeout = config.ReducedPingTimeout; AllCostTimeout = config.AllCostTimeout; NetworkDropThreshold = config.NetworkDropThreshold; OverflowDropThreshold = config.OverflowDropThreshold; MaxConnectionAttempt = config.MaxConnectionAttempt; AckDelay = config.AckDelay; SendDelay = config.SendDelay; MaxCombinedReliableMessageSize = config.MaxCombinedReliableMessageSize; MaxCombinedReliableMessageCount = config.MaxCombinedReliableMessageCount; MaxSentMessageQueueSize = config.MaxSentMessageQueueSize; AcksType = (byte)config.AcksType; UsePlatformSpecificProtocols = config.UsePlatformSpecificProtocols; InitialBandwidth = config.InitialBandwidth; BandwidthPeakFactor = config.BandwidthPeakFactor; WebSocketReceiveBufferMaxSize = config.WebSocketReceiveBufferMaxSize; UdpSocketReceiveBufferMaxSize = config.UdpSocketReceiveBufferMaxSize; if (config.SSLCertFilePath != null) { int num = SetSSLCertFilePath(config.SSLCertFilePath); if (num != 0) { throw new ArgumentOutOfRangeException("SSLCertFilePath cannot be > than " + num); } } if (config.SSLPrivateKeyFilePath != null) { int num2 = SetSSLPrivateKeyFilePath(config.SSLPrivateKeyFilePath); if (num2 != 0) { throw new ArgumentOutOfRangeException("SSLPrivateKeyFilePath cannot be > than " + num2); } } if (config.SSLCAFilePath != null) { int num3 = SetSSLCAFilePath(config.SSLCAFilePath); if (num3 != 0) { throw new ArgumentOutOfRangeException("SSLCAFilePath cannot be > than " + num3); } } for (byte b = 0; b < config.ChannelCount; b++) { AddChannel((byte)config.GetChannel(b)); } for (byte b2 = 0; b2 < config.SharedOrderChannelCount; b2++) { IList sharedOrderChannels = config.GetSharedOrderChannels(b2); byte[] array = new byte[sharedOrderChannels.Count]; sharedOrderChannels.CopyTo(array, 0); MakeChannelsSharedOrder(array); } } protected virtual void Dispose(bool disposing) { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } ~ConnectionConfigInternal() { Dispose(disposing: false); } public void Dispose() { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr InternalCreate(); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod(IsThreadSafe = true)] private static extern void InternalDestroy(IntPtr ptr); [MethodImpl(MethodImplOptions.InternalCall)] public extern byte AddChannel(int value); [MethodImpl(MethodImplOptions.InternalCall)] public extern bool SetPacketSize(ushort value); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod("SetSSLCertFilePath")] public extern int SetSSLCertFilePath(string value); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod("SetSSLPrivateKeyFilePath")] public extern int SetSSLPrivateKeyFilePath(string value); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod("SetSSLCAFilePath")] public extern int SetSSLCAFilePath(string value); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod("MakeChannelsSharedOrder")] private extern bool MakeChannelsSharedOrder(byte[] values); } [NativeHeader("Modules/UNET/UNETConfiguration.h")] [NativeConditional("ENABLE_NETWORK && ENABLE_UNET", true)] internal class HostTopologyInternal : IDisposable { public IntPtr m_Ptr; [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort ReceivedMessagePoolSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort SentMessagePoolSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern float MessagePoolSizeGrowthFactor { [MethodImpl(MethodImplOptions.InternalCall)] set; } public HostTopologyInternal(HostTopology topology) { ConnectionConfigInternal config = new ConnectionConfigInternal(topology.DefaultConfig); m_Ptr = InternalCreate(config, topology.MaxDefaultConnections); for (int i = 1; i <= topology.SpecialConnectionConfigsCount; i++) { ConnectionConfig specialConnectionConfig = topology.GetSpecialConnectionConfig(i); ConnectionConfigInternal config2 = new ConnectionConfigInternal(specialConnectionConfig); AddSpecialConnectionConfig(config2); } ReceivedMessagePoolSize = topology.ReceivedMessagePoolSize; SentMessagePoolSize = topology.SentMessagePoolSize; MessagePoolSizeGrowthFactor = topology.MessagePoolSizeGrowthFactor; } protected virtual void Dispose(bool disposing) { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } ~HostTopologyInternal() { Dispose(disposing: false); } public void Dispose() { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr InternalCreate(ConnectionConfigInternal config, int maxDefaultConnections); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod(IsThreadSafe = true)] private static extern void InternalDestroy(IntPtr ptr); [MethodImpl(MethodImplOptions.InternalCall)] public extern ushort AddSpecialConnectionConfig(ConnectionConfigInternal config); } [NativeConditional("ENABLE_NETWORK && ENABLE_UNET", true)] [NativeHeader("Modules/UNET/UNETConfiguration.h")] internal class ConnectionSimulatorConfigInternal : IDisposable { public IntPtr m_Ptr; public ConnectionSimulatorConfigInternal(ConnectionSimulatorConfig config) { m_Ptr = InternalCreate(config.m_OutMinDelay, config.m_OutAvgDelay, config.m_InMinDelay, config.m_InAvgDelay, config.m_PacketLossPercentage); } protected virtual void Dispose(bool disposing) { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } GC.SuppressFinalize(this); } ~ConnectionSimulatorConfigInternal() { Dispose(disposing: false); } public void Dispose() { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr InternalCreate(int outMinDelay, int outAvgDelay, int inMinDelay, int inAvgDelay, float packetLossPercentage); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod(IsThreadSafe = true)] private static extern void InternalDestroy(IntPtr ptr); } [NativeConditional("ENABLE_NETWORK && ENABLE_UNET", true)] [NativeHeader("Modules/UNET/UNETConfiguration.h")] internal class GlobalConfigInternal : IDisposable { public IntPtr m_Ptr; [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint ThreadAwakeTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte ReactorModel { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort ReactorMaximumReceivedMessages { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort ReactorMaximumSentMessages { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort MaxPacketSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern ushort MaxHosts { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern byte ThreadPoolSize { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint MinTimerTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint MaxTimerTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint MinNetSimulatorTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } [NativeProperty(/*Could not decode attribute arguments.*/)] private extern uint MaxNetSimulatorTimeout { [MethodImpl(MethodImplOptions.InternalCall)] set; } public GlobalConfigInternal(GlobalConfig config) { if (config == null) { throw new NullReferenceException("config is not defined"); } m_Ptr = InternalCreate(); ThreadAwakeTimeout = config.ThreadAwakeTimeout; ReactorModel = (byte)config.ReactorModel; ReactorMaximumReceivedMessages = config.ReactorMaximumReceivedMessages; ReactorMaximumSentMessages = config.ReactorMaximumSentMessages; MaxPacketSize = config.MaxPacketSize; MaxHosts = config.MaxHosts; if (config.ThreadPoolSize == 0 || config.ThreadPoolSize > 254) { throw new ArgumentOutOfRangeException("Worker thread pool size should be >= 1 && < 254 (for server only)"); } byte threadPoolSize = config.ThreadPoolSize; ThreadPoolSize = threadPoolSize; MinTimerTimeout = config.MinTimerTimeout; MaxTimerTimeout = config.MaxTimerTimeout; MinNetSimulatorTimeout = config.MinNetSimulatorTimeout; MaxNetSimulatorTimeout = config.MaxNetSimulatorTimeout; } protected virtual void Dispose(bool disposing) { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } ~GlobalConfigInternal() { Dispose(disposing: false); } public void Dispose() { if (m_Ptr != IntPtr.Zero) { InternalDestroy(m_Ptr); m_Ptr = IntPtr.Zero; } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr InternalCreate(); [MethodImpl(MethodImplOptions.InternalCall)] [NativeMethod(IsThreadSafe = true)] private static extern void InternalDestroy(IntPtr ptr); } } namespace UnityEngine.Networking.Types { [DefaultValue(NetworkAccessLevel.Invalid)] public enum NetworkAccessLevel : ulong { Invalid = 0uL, User = 1uL, Owner = 2uL, Admin = 4uL } [DefaultValue(AppID.Invalid)] public enum AppID : ulong { Invalid = ulong.MaxValue } [DefaultValue(SourceID.Invalid)] public enum SourceID : ulong { Invalid = ulong.MaxValue } [DefaultValue(NetworkID.Invalid)] public enum NetworkID : ulong { Invalid = ulong.MaxValue } [DefaultValue(NodeID.Invalid)] public enum NodeID : ushort { Invalid } [DefaultValue(HostPriority.Invalid)] public enum HostPriority { Invalid = int.MaxValue } public class NetworkAccessToken { private const int NETWORK_ACCESS_TOKEN_SIZE = 64; public byte[] array; public NetworkAccessToken() { array = new byte[64]; } public NetworkAccessToken(byte[] array) { this.array = array; } public NetworkAccessToken(string strArray) { try { array = Convert.FromBase64String(strArray); } catch (Exception) { array = new byte[64]; } } public string GetByteString() { return Convert.ToBase64String(array); } public bool IsValid() { if (this.array == null || this.array.Length != 64) { return false; } bool result = false; byte[] array = this.array; for (int i = 0; i < array.Length; i++) { if (array[i] != 0) { result = true; break; } } return result; } } } namespace UnityEngine.Networking.Match { [Obsolete("The matchmaker and relay feature will be removed in the future, minimal support will continue until this can be safely done.")] public class MatchInfo { public string address { get; private set; } public int port { get; private set; } public int domain { get; private set; } public NetworkID networkId { get; private set; } public NetworkAccessToken accessToken { get; private set; } public NodeID nodeId { get; private set; } public bool usingRelay { get; private set; } public MatchInfo() { } internal MatchInfo(CreateMatchResponse matchResponse) { address = matchResponse.address; port = matchResponse.port; domain = matchResponse.domain; networkId = (NetworkID)matchResponse.networkId; accessToken = new NetworkAccessToken(matchResponse.accessTokenString); nodeId = matchResponse.nodeId; usingRelay = matchResponse.usingRelay; } internal MatchInfo(JoinMatchResponse matchResponse) { address = matchResponse.address; port = matchResponse.port; domain = matchResponse.domain; networkId = (NetworkID)matchResponse.networkId; accessToken = new NetworkAccessToken(matchResponse.accessTokenString); nodeId = matchResponse.nodeId; usingRelay = matchResponse.usingRelay; } public override string ToString() { return UnityString.Format("{0} @ {1}:{2} [{3},{4}]", new object[5] { networkId, address, port, nodeId, usingRelay }); } } [Obsolete("The matchmaker and relay feature will be removed in the future, minimal support will continue until this can be safely done.")] public class MatchInfoSnapshot { public class MatchInfoDirectConnectSnapshot { public NodeID nodeId { get; private set; } public string publicAddress { get; private set; } public string privateAddress { get; private set; } public HostPriority hostPriority { get; private set; } public MatchInfoDirectConnectSnapshot() { } internal MatchInfoDirectConnectSnapshot(MatchDirectConnectInfo matchDirectConnectInfo) { nodeId = matchDirectConnectInfo.nodeId; publicAddress = matchDirectConnectInfo.publicAddress; privateAddress = matchDirectConnectInfo.privateAddress; hostPriority = matchDirectConnectInfo.hostPriority; } } public NetworkID networkId { get; private set; } public NodeID hostNodeId { get; private set; } public string name { get; private set; } public int averageEloScore { get; private set; } public int maxSize { get; private set; } public int currentSize { get; private set; } public bool isPrivate { get; private set; } public Dictionary matchAttributes { get; private set; } public List directConnectInfos { get; private set; } public MatchInfoSnapshot() { } internal MatchInfoSnapshot(MatchDesc matchDesc) { networkId = (NetworkID)matchDesc.networkId; hostNodeId = matchDesc.hostNodeId; name = matchDesc.name; averageEloScore = matchDesc.averageEloScore; maxSize = matchDesc.maxSize; currentSize = matchDesc.currentSize; isPrivate = matchDesc.isPrivate; matchAttributes = matchDesc.matchAttributes; directConnectInfos = new List(); foreach (MatchDirectConnectInfo directConnectInfo in matchDesc.directConnectInfos) { directConnectInfos.Add(new MatchInfoDirectConnectSnapshot(directConnectInfo)); } } } [Obsolete("The matchmaker and relay feature will be removed in the future, minimal support will continue until this can be safely done.")] public class NetworkMatch : MonoBehaviour { public delegate void BasicResponseDelegate(bool success, string extendedInfo); public delegate void DataResponseDelegate(bool success, string extendedInfo, T responseData); private delegate void InternalResponseDelegate(T response, U userCallback); private Uri m_BaseUri = new Uri("https://mm.unet.unity3d.com"); public Uri baseUri { get { return m_BaseUri; } set { m_BaseUri = value; } } [Obsolete("This function is not used any longer to interface with the matchmaker. Please set up your project by logging in through the editor connect dialog.", true)] [EditorBrowsable(EditorBrowsableState.Never)] public void SetProgramAppID(AppID programAppID) { } public Coroutine CreateMatch(string matchName, uint matchSize, bool matchAdvertise, string matchPassword, string publicClientAddress, string privateClientAddress, int eloScoreForMatch, int requestDomain, DataResponseDelegate callback) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 if ((int)Application.platform == 17) { Debug.LogError((object)"Matchmaking is not supported on WebGL player."); return null; } return CreateMatch(new CreateMatchRequest { name = matchName, size = matchSize, advertise = matchAdvertise, password = matchPassword, publicAddress = publicClientAddress, privateAddress = privateClientAddress, eloScore = eloScoreForMatch, domain = requestDomain }, callback); } internal Coroutine CreateMatch(CreateMatchRequest req, DataResponseDelegate callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting CreateMatch Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/CreateMatchRequest"); Debug.Log((object)("MatchMakingClient Create :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", 0); val.AddField("domain", req.domain); val.AddField("name", req.name); val.AddField("size", req.size.ToString()); val.AddField("advertise", req.advertise.ToString()); val.AddField("password", req.password); val.AddField("publicAddress", req.publicAddress); val.AddField("privateAddress", req.privateAddress); val.AddField("eloScore", req.eloScore.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse>(client, OnMatchCreate, callback)); } internal virtual void OnMatchCreate(CreateMatchResponse response, DataResponseDelegate userCallback) { if (response.success) { Utility.SetAccessTokenForNetwork((NetworkID)response.networkId, new NetworkAccessToken(response.accessTokenString)); } userCallback(response.success, response.extendedInfo, new MatchInfo(response)); } public Coroutine JoinMatch(NetworkID netId, string matchPassword, string publicClientAddress, string privateClientAddress, int eloScoreForClient, int requestDomain, DataResponseDelegate callback) { return JoinMatch(new JoinMatchRequest { networkId = netId, password = matchPassword, publicAddress = publicClientAddress, privateAddress = privateClientAddress, eloScore = eloScoreForClient, domain = requestDomain }, callback); } internal Coroutine JoinMatch(JoinMatchRequest req, DataResponseDelegate callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting JoinMatch Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/JoinMatchRequest"); Debug.Log((object)("MatchMakingClient Join :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", 0); val.AddField("domain", req.domain); val.AddField("networkId", req.networkId.ToString()); val.AddField("password", req.password); val.AddField("publicAddress", req.publicAddress); val.AddField("privateAddress", req.privateAddress); val.AddField("eloScore", req.eloScore.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse>(client, OnMatchJoined, callback)); } internal void OnMatchJoined(JoinMatchResponse response, DataResponseDelegate userCallback) { if (response.success) { Utility.SetAccessTokenForNetwork((NetworkID)response.networkId, new NetworkAccessToken(response.accessTokenString)); } userCallback(response.success, response.extendedInfo, new MatchInfo(response)); } public Coroutine DestroyMatch(NetworkID netId, int requestDomain, BasicResponseDelegate callback) { return DestroyMatch(new DestroyMatchRequest { networkId = netId, domain = requestDomain }, callback); } internal Coroutine DestroyMatch(DestroyMatchRequest req, BasicResponseDelegate callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting DestroyMatch Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/DestroyMatchRequest"); Debug.Log((object)("MatchMakingClient Destroy :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", Utility.GetAccessTokenForNetwork(req.networkId).GetByteString()); val.AddField("domain", req.domain); val.AddField("networkId", req.networkId.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse(client, OnMatchDestroyed, callback)); } internal void OnMatchDestroyed(BasicResponse response, BasicResponseDelegate userCallback) { userCallback(response.success, response.extendedInfo); } public Coroutine DropConnection(NetworkID netId, NodeID dropNodeId, int requestDomain, BasicResponseDelegate callback) { return DropConnection(new DropConnectionRequest { networkId = netId, nodeId = dropNodeId, domain = requestDomain }, callback); } internal Coroutine DropConnection(DropConnectionRequest req, BasicResponseDelegate callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting DropConnection Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/DropConnectionRequest"); Debug.Log((object)("MatchMakingClient DropConnection :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", Utility.GetAccessTokenForNetwork(req.networkId).GetByteString()); val.AddField("domain", req.domain); val.AddField("networkId", req.networkId.ToString()); val.AddField("nodeId", req.nodeId.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse(client, OnDropConnection, callback)); } internal void OnDropConnection(DropConnectionResponse response, BasicResponseDelegate userCallback) { userCallback(response.success, response.extendedInfo); } public Coroutine ListMatches(int startPageNumber, int resultPageSize, string matchNameFilter, bool filterOutPrivateMatchesFromResults, int eloScoreTarget, int requestDomain, DataResponseDelegate> callback) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 if ((int)Application.platform == 17) { Debug.LogError((object)"Matchmaking is not supported on WebGL player."); return null; } return ListMatches(new ListMatchRequest { pageNum = startPageNumber, pageSize = resultPageSize, nameFilter = matchNameFilter, filterOutPrivateMatches = filterOutPrivateMatchesFromResults, eloScore = eloScoreTarget, domain = requestDomain }, callback); } internal Coroutine ListMatches(ListMatchRequest req, DataResponseDelegate> callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting ListMatch Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/ListMatchRequest"); Debug.Log((object)("MatchMakingClient ListMatches :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", 0); val.AddField("domain", req.domain); val.AddField("pageSize", req.pageSize); val.AddField("pageNum", req.pageNum); val.AddField("nameFilter", req.nameFilter); val.AddField("filterOutPrivateMatches", req.filterOutPrivateMatches.ToString()); val.AddField("eloScore", req.eloScore.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse>>(client, OnMatchList, callback)); } internal void OnMatchList(ListMatchResponse response, DataResponseDelegate> userCallback) { List list = new List(); foreach (MatchDesc match in response.matches) { list.Add(new MatchInfoSnapshot(match)); } userCallback(response.success, response.extendedInfo, list); } public Coroutine SetMatchAttributes(NetworkID networkId, bool isListed, int requestDomain, BasicResponseDelegate callback) { return SetMatchAttributes(new SetMatchAttributesRequest { networkId = networkId, isListed = isListed, domain = requestDomain }, callback); } internal Coroutine SetMatchAttributes(SetMatchAttributesRequest req, BasicResponseDelegate callback) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if (callback == null) { Debug.Log((object)"callback supplied is null, aborting SetMatchAttributes Request."); return null; } Uri uri = new Uri(baseUri, "/json/reply/SetMatchAttributesRequest"); Debug.Log((object)("MatchMakingClient SetMatchAttributes :" + uri)); WWWForm val = new WWWForm(); val.AddField("version", Request.currentVersion); val.AddField("projectId", Application.cloudProjectId); val.AddField("sourceId", Utility.GetSourceID().ToString()); val.AddField("accessTokenString", Utility.GetAccessTokenForNetwork(req.networkId).GetByteString()); val.AddField("domain", req.domain); val.AddField("networkId", req.networkId.ToString()); val.AddField("isListed", req.isListed.ToString()); val.headers["Accept"] = "application/json"; UnityWebRequest client = UnityWebRequest.Post(uri.ToString(), val); return ((MonoBehaviour)this).StartCoroutine(ProcessMatchResponse(client, OnSetMatchAttributes, callback)); } internal void OnSetMatchAttributes(BasicResponse response, BasicResponseDelegate userCallback) { userCallback(response.success, response.extendedInfo); } private IEnumerator ProcessMatchResponse(UnityWebRequest client, InternalResponseDelegate internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new() { yield return client.SendWebRequest(); JSONRESPONSE jsonInterface = new JSONRESPONSE(); if ((int)client.result == 1) { try { JsonUtility.FromJsonOverwrite(client.downloadHandler.text, (object)jsonInterface); } catch (ArgumentException ex) { ArgumentException exception = ex; jsonInterface.SetFailure(UnityString.Format("ArgumentException:[{0}] ", new object[1] { exception.ToString() })); } } else { jsonInterface.SetFailure(UnityString.Format("Request error:[{0}] Raw response:[{1}]", new object[2] { client.error, client.downloadHandler.text })); } client.Dispose(); internalCallback(jsonInterface, userCallback); } } internal abstract class Request { public static readonly int currentVersion = 3; public int version { get; set; } public SourceID sourceId { get; set; } public string projectId { get; set; } public AppID appId { get; set; } public string accessTokenString { get; set; } public int domain { get; set; } public virtual bool IsValid() { return sourceId != SourceID.Invalid; } public override string ToString() { return UnityString.Format("[{0}]-SourceID:0x{1},projectId:{2},accessTokenString.IsEmpty:{3},domain:{4}", new object[5] { base.ToString(), sourceId.ToString("X"), projectId, string.IsNullOrEmpty(accessTokenString), domain }); } } internal interface IResponse { void SetSuccess(); void SetFailure(string info); } [Serializable] internal abstract class Response : IResponse { public bool success; public string extendedInfo; public void SetSuccess() { success = true; extendedInfo = ""; } public void SetFailure(string info) { success = false; extendedInfo += info; } public override string ToString() { return UnityString.Format("[{0}]-success:{1}-extendedInfo:{2}", new object[3] { base.ToString(), success, extendedInfo }); } } internal class BasicResponse : Response { } internal class CreateMatchRequest : Request { public string name { get; set; } public uint size { get; set; } public string publicAddress { get; set; } public string privateAddress { get; set; } public int eloScore { get; set; } public bool advertise { get; set; } public string password { get; set; } public Dictionary matchAttributes { get; set; } public override string ToString() { return UnityString.Format("[{0}]-name:{1},size:{2},publicAddress:{3},privateAddress:{4},eloScore:{5},advertise:{6},HasPassword:{7},matchAttributes.Count:{8}", new object[9] { base.ToString(), name, size, publicAddress, privateAddress, eloScore, advertise, string.IsNullOrEmpty(password) ? "NO" : "YES", (matchAttributes != null) ? matchAttributes.Count : 0 }); } public override bool IsValid() { return base.IsValid() && size >= 2 && (matchAttributes == null || matchAttributes.Count <= 10); } } internal class CreateMatchResponse : BasicResponse { public string address; public int port; public int domain = 0; public ulong networkId; public string accessTokenString; public NodeID nodeId; public bool usingRelay; public override string ToString() { return UnityString.Format("[{0}]-address:{1},port:{2},networkId:0x{3},accessTokenString.IsEmpty:{4},nodeId:0x{5},usingRelay:{6}", new object[7] { base.ToString(), address, port, networkId.ToString("X"), string.IsNullOrEmpty(accessTokenString), nodeId.ToString("X"), usingRelay }); } } internal class JoinMatchRequest : Request { public NetworkID networkId { get; set; } public string publicAddress { get; set; } public string privateAddress { get; set; } public int eloScore { get; set; } public string password { get; set; } public override string ToString() { return UnityString.Format("[{0}]-networkId:0x{1},publicAddress:{2},privateAddress:{3},eloScore:{4},HasPassword:{5}", new object[6] { base.ToString(), networkId.ToString("X"), publicAddress, privateAddress, eloScore, string.IsNullOrEmpty(password) ? "NO" : "YES" }); } public override bool IsValid() { return base.IsValid() && networkId != NetworkID.Invalid; } } [Serializable] internal class JoinMatchResponse : BasicResponse { public string address; public int port; public int domain = 0; public ulong networkId; public string accessTokenString; public NodeID nodeId; public bool usingRelay; public override string ToString() { return UnityString.Format("[{0}]-address:{1},port:{2},networkId:0x{3},accessTokenString.IsEmpty:{4},nodeId:0x{5},usingRelay:{6}", new object[7] { base.ToString(), address, port, networkId.ToString("X"), string.IsNullOrEmpty(accessTokenString), nodeId.ToString("X"), usingRelay }); } } internal class DestroyMatchRequest : Request { public NetworkID networkId { get; set; } public override string ToString() { return UnityString.Format("[{0}]-networkId:0x{1}", new object[2] { base.ToString(), networkId.ToString("X") }); } public override bool IsValid() { return base.IsValid() && networkId != NetworkID.Invalid; } } internal class DropConnectionRequest : Request { public NetworkID networkId { get; set; } public NodeID nodeId { get; set; } public override string ToString() { return UnityString.Format("[{0}]-networkId:0x{1},nodeId:0x{2}", new object[3] { base.ToString(), networkId.ToString("X"), nodeId.ToString("X") }); } public override bool IsValid() { return base.IsValid() && networkId != NetworkID.Invalid && nodeId != NodeID.Invalid; } } [Serializable] internal class DropConnectionResponse : Response { public ulong networkId; public NodeID nodeId; public override string ToString() { return UnityString.Format("[{0}]-networkId:{1}", new object[2] { base.ToString(), networkId.ToString("X") }); } } internal class ListMatchRequest : Request { [Obsolete("This bool is deprecated in favor of filterOutPrivateMatches")] public bool includePasswordMatches; public int pageSize { get; set; } public int pageNum { get; set; } public string nameFilter { get; set; } public bool filterOutPrivateMatches { get; set; } public int eloScore { get; set; } public Dictionary matchAttributeFilterLessThan { get; set; } public Dictionary matchAttributeFilterEqualTo { get; set; } public Dictionary matchAttributeFilterGreaterThan { get; set; } public override string ToString() { return UnityString.Format("[{0}]-pageSize:{1},pageNum:{2},nameFilter:{3}, filterOutPrivateMatches:{4}, eloScore:{5}, matchAttributeFilterLessThan.Count:{6}, matchAttributeFilterEqualTo.Count:{7}, matchAttributeFilterGreaterThan.Count:{8}", new object[9] { base.ToString(), pageSize, pageNum, nameFilter, filterOutPrivateMatches, eloScore, (matchAttributeFilterLessThan != null) ? matchAttributeFilterLessThan.Count : 0, (matchAttributeFilterEqualTo != null) ? matchAttributeFilterEqualTo.Count : 0, (matchAttributeFilterGreaterThan != null) ? matchAttributeFilterGreaterThan.Count : 0 }); } public override bool IsValid() { int num = ((matchAttributeFilterLessThan != null) ? matchAttributeFilterLessThan.Count : 0); num += ((matchAttributeFilterEqualTo != null) ? matchAttributeFilterEqualTo.Count : 0); num += ((matchAttributeFilterGreaterThan != null) ? matchAttributeFilterGreaterThan.Count : 0); return base.IsValid() && pageSize >= 1 && pageSize <= 1000 && num <= 10; } } [Serializable] internal class MatchDirectConnectInfo { public NodeID nodeId; public string publicAddress; public string privateAddress; public HostPriority hostPriority; public override string ToString() { return UnityString.Format("[{0}]-nodeId:{1},publicAddress:{2},privateAddress:{3},hostPriority:{4}", new object[5] { base.ToString(), nodeId, publicAddress, privateAddress, hostPriority }); } } [Serializable] internal class MatchDesc { public ulong networkId; public string name; public int averageEloScore; public int maxSize; public int currentSize; public bool isPrivate; public Dictionary matchAttributes; public NodeID hostNodeId; public List directConnectInfos; public override string ToString() { return UnityString.Format("[{0}]-networkId:0x{1},name:{2},averageEloScore:{3},maxSize:{4},currentSize:{5},isPrivate:{6},matchAttributes.Count:{7},hostNodeId:{8},directConnectInfos.Count:{9}", new object[10] { base.ToString(), networkId.ToString("X"), name, averageEloScore, maxSize, currentSize, isPrivate, (matchAttributes != null) ? matchAttributes.Count : 0, hostNodeId, directConnectInfos.Count }); } } [Serializable] internal class ListMatchResponse : BasicResponse { public List matches; public ListMatchResponse() { matches = new List(); } public ListMatchResponse(List otherMatches) { matches = otherMatches; } public override string ToString() { return UnityString.Format("[{0}]-matches.Count:{1}", new object[2] { base.ToString(), (matches != null) ? matches.Count : 0 }); } } internal class CreateOrJoinMatchRequest : CreateMatchRequest { } internal class SetMatchAttributesRequest : Request { public NetworkID networkId { get; set; } public bool isListed { get; set; } public override string ToString() { return UnityString.Format("[{0}]-networkId:{1},isListed:{2}", new object[3] { base.ToString(), networkId.ToString("X"), isListed }); } public override bool IsValid() { return base.IsValid() && networkId != NetworkID.Invalid; } } }