From c56b23b34cb0eed0264bb9e281581a88db3f0222 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 7 Dec 2020 20:47:07 +0000 Subject: [PATCH] cleanup --- QuantumUNET/QSBNetworkClient.cs | 6 - QuantumUNET/QSBNetworkManagerHUD.cs | 154 +-- QuantumUNET/QSBNetworkManagerUNET.cs | 1016 +++----------------- QuantumUNET/QSBNetworkMigrationManager.cs | 1066 --------------------- QuantumUNET/QSBPeerAuthorityMessage.cs | 27 - QuantumUNET/QSBPeerListMessage.cs | 32 - QuantumUNET/QuantumUNET.csproj | 3 - 7 files changed, 189 insertions(+), 2115 deletions(-) delete mode 100644 QuantumUNET/QSBNetworkMigrationManager.cs delete mode 100644 QuantumUNET/QSBPeerAuthorityMessage.cs delete mode 100644 QuantumUNET/QSBPeerListMessage.cs diff --git a/QuantumUNET/QSBNetworkClient.cs b/QuantumUNET/QSBNetworkClient.cs index 8acce412..e6e4cc2b 100644 --- a/QuantumUNET/QSBNetworkClient.cs +++ b/QuantumUNET/QSBNetworkClient.cs @@ -170,12 +170,6 @@ namespace QuantumUNET return true; } - public void Connect(MatchInfo matchInfo) - { - PrepareForConnect(); - ConnectWithRelay(matchInfo); - } - public bool ReconnectToNewHost(string serverIp, int serverPort) { bool result; diff --git a/QuantumUNET/QSBNetworkManagerHUD.cs b/QuantumUNET/QSBNetworkManagerHUD.cs index d3015c63..78aed10d 100644 --- a/QuantumUNET/QSBNetworkManagerHUD.cs +++ b/QuantumUNET/QSBNetworkManagerHUD.cs @@ -8,62 +8,62 @@ namespace QuantumUNET { private void Awake() { - this.manager = base.GetComponent(); + manager = GetComponent(); } private void OnGUI() { - if (this.showGUI) + if (showGUI) { - int num = 10 + this.offsetX; - int num2 = 40 + this.offsetY; - bool flag = this.manager.client == null || this.manager.client.connection == null || this.manager.client.connection.connectionId == -1; - if (!this.manager.IsClientConnected() && !QSBNetworkServer.active && this.manager.matchMaker == null) + var num = 10 + offsetX; + var num2 = 40 + offsetY; + var flag = manager.client == null || manager.client.connection == null || manager.client.connection.connectionId == -1; + if (!manager.IsClientConnected() && !QSBNetworkServer.active) { if (flag) { if (Application.platform != RuntimePlatform.WebGLPlayer) { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Host(H)")) + if (GUI.Button(new Rect(num, num2, 200f, 20f), "Host")) { - this.manager.StartHost(); + manager.StartHost(); } num2 += 24; } - if (GUI.Button(new Rect((float)num, (float)num2, 105f, 20f), "LAN Client(C)")) + if (GUI.Button(new Rect(num, num2, 105f, 20f), "Connect")) { - this.manager.StartClient(); + manager.StartClient(); } - this.manager.networkAddress = GUI.TextField(new Rect((float)(num + 100), (float)num2, 95f, 20f), this.manager.networkAddress); + manager.networkAddress = GUI.TextField(new Rect(num + 100, num2, 95f, 20f), manager.networkAddress); num2 += 24; if (Application.platform == RuntimePlatform.WebGLPlayer) { - GUI.Box(new Rect((float)num, (float)num2, 200f, 25f), "( WebGL cannot be server )"); + GUI.Box(new Rect(num, num2, 200f, 25f), "( WebGL cannot be server )"); num2 += 24; } else { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Server Only(S)")) + if (GUI.Button(new Rect(num, num2, 200f, 20f), "LAN Server Only")) { - this.manager.StartServer(); + manager.StartServer(); } num2 += 24; } } else { - GUI.Label(new Rect((float)num, (float)num2, 200f, 20f), string.Concat(new object[] + GUI.Label(new Rect(num, num2, 200f, 20f), string.Concat(new object[] { "Connecting to ", - this.manager.networkAddress, + manager.networkAddress, ":", - this.manager.networkPort, + manager.networkPort, ".." })); num2 += 24; - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Cancel Connection Attempt")) + if (GUI.Button(new Rect(num, num2, 200f, 20f), "Cancel Connection Attempt")) { - this.manager.StopClient(); + manager.StopClient(); } } } @@ -71,31 +71,25 @@ namespace QuantumUNET { if (QSBNetworkServer.active) { - string text = "Server: port=" + this.manager.networkPort; - if (this.manager.useWebSockets) + var text = $"Hosting on port {manager.networkPort}"; + if (manager.useWebSockets) { - text += " (Using WebSockets)"; + text += " (using WebSockets)"; } - GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), text); + GUI.Label(new Rect(num, num2, 300f, 20f), text); num2 += 24; } - if (this.manager.IsClientConnected()) + if (manager.IsClientConnected()) { - GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), string.Concat(new object[] - { - "Client: address=", - this.manager.networkAddress, - " port=", - this.manager.networkPort - })); + GUI.Label(new Rect(num, num2, 300f, 20f), $"Connected to {manager.networkAddress}, port {manager.networkPort}"); num2 += 24; } } - if (this.manager.IsClientConnected() && !QSBClientScene.ready) + if (manager.IsClientConnected() && !QSBClientScene.ready) { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Client Ready")) + if (GUI.Button(new Rect(num, num2, 200f, 20f), "Client Ready")) { - QSBClientScene.Ready(this.manager.client.connection); + QSBClientScene.Ready(manager.client.connection); if (QSBClientScene.localPlayers.Count == 0) { QSBClientScene.AddPlayer(0); @@ -103,102 +97,20 @@ namespace QuantumUNET } num2 += 24; } - if (QSBNetworkServer.active || this.manager.IsClientConnected()) + if (QSBNetworkServer.active || manager.IsClientConnected()) { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Stop (X)")) + if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop")) { - this.manager.StopHost(); + manager.StopHost(); } num2 += 24; } - if (!QSBNetworkServer.active && !this.manager.IsClientConnected() && flag) + if (!QSBNetworkServer.active && !manager.IsClientConnected() && flag) { num2 += 10; if (Application.platform == RuntimePlatform.WebGLPlayer) { - GUI.Box(new Rect((float)(num - 5), (float)num2, 220f, 25f), "(WebGL cannot use Match Maker)"); - } - else if (this.manager.matchMaker == null) - { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Enable Match Maker (M)")) - { - this.manager.StartMatchMaker(); - } - num2 += 24; - } - else - { - if (this.manager.matchInfo == null) - { - if (this.manager.matches == null) - { - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Create Internet Match")) - { - this.manager.matchMaker.CreateMatch(this.manager.matchName, this.manager.matchSize, true, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate(this.manager.OnMatchCreate)); - } - num2 += 24; - GUI.Label(new Rect((float)num, (float)num2, 100f, 20f), "Room Name:"); - this.manager.matchName = GUI.TextField(new Rect((float)(num + 100), (float)num2, 100f, 20f), this.manager.matchName); - num2 += 24; - num2 += 10; - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Find Internet Match")) - { - this.manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, new NetworkMatch.DataResponseDelegate>(this.manager.OnMatchList)); - } - num2 += 24; - } - else - { - for (int i = 0; i < this.manager.matches.Count; i++) - { - MatchInfoSnapshot matchInfoSnapshot = this.manager.matches[i]; - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Join Match:" + matchInfoSnapshot.name)) - { - this.manager.matchName = matchInfoSnapshot.name; - this.manager.matchMaker.JoinMatch(matchInfoSnapshot.networkId, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate(this.manager.OnMatchJoined)); - } - num2 += 24; - } - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Back to Match Menu")) - { - this.manager.matches = null; - } - num2 += 24; - } - } - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Change MM server")) - { - this.m_ShowServer = !this.m_ShowServer; - } - if (this.m_ShowServer) - { - num2 += 24; - if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Local")) - { - this.manager.SetMatchHost("localhost", 1337, false); - this.m_ShowServer = false; - } - num2 += 24; - if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Internet")) - { - this.manager.SetMatchHost("mm.unet.unity3d.com", 443, true); - this.m_ShowServer = false; - } - num2 += 24; - if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Staging")) - { - this.manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true); - this.m_ShowServer = false; - } - } - num2 += 24; - GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), "MM Uri: " + this.manager.matchMaker.baseUri); - num2 += 24; - if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Disable Match Maker")) - { - this.manager.StopMatchMaker(); - } - num2 += 24; + GUI.Box(new Rect(num - 5, num2, 220f, 25f), "(WebGL cannot use Match Maker)"); } } } diff --git a/QuantumUNET/QSBNetworkManagerUNET.cs b/QuantumUNET/QSBNetworkManagerUNET.cs index dac24195..8e8cb471 100644 --- a/QuantumUNET/QSBNetworkManagerUNET.cs +++ b/QuantumUNET/QSBNetworkManagerUNET.cs @@ -5,201 +5,53 @@ using System.Net; using UnityEngine; using UnityEngine.Networking; using UnityEngine.Networking.Match; -using UnityEngine.Networking.Types; using UnityEngine.SceneManagement; namespace QuantumUNET { public class QSBNetworkManagerUNET : MonoBehaviour { - public int networkPort - { - get - { - return m_NetworkPort; - } - set - { - m_NetworkPort = value; - } - } + public static QSBNetworkManagerUNET singleton; + public static string networkSceneName = ""; - public bool serverBindToIP - { - get - { - return m_ServerBindToIP; - } - set - { - m_ServerBindToIP = value; - } - } + public int networkPort { get; set; } = 7777; + public int simulatedLatency { get; set; } = 1; + public bool serverBindToIP { get; set; } + public bool dontDestroyOnLoad { get; set; } = true; + public bool runInBackground { get; set; } = true; + public bool scriptCRCCheck { get; set; } = true; + public bool autoCreatePlayer { get; set; } = true; + public bool isNetworkActive; + public bool useWebSockets { get; set; } + public bool useSimulator { get; set; } + public bool clientLoadedScene { get; set; } + public string serverBindAddress { get; set; } = ""; + public string networkAddress { get; set; } = "localhost"; + public string offlineScene { get; set; } = ""; + public string onlineScene { get; set; } = ""; + public float packetLossPercentage { get; set; } + public float maxDelay { get; set; } = 0.01f; + public GameObject playerPrefab { get; set; } + public PlayerSpawnMethod playerSpawnMethod { get; set; } + public List spawnPrefabs { get; } = new List(); + public string matchName = "default"; + public uint matchSize = 4U; + public QSBNetworkClient client; + public int maxConnections { get; set; } = 4; + public List channels { get; } = new List(); - public string serverBindAddress - { - get - { - return m_ServerBindAddress; - } - set - { - m_ServerBindAddress = value; - } - } - - public string networkAddress - { - get - { - return m_NetworkAddress; - } - set - { - m_NetworkAddress = value; - } - } - - public bool dontDestroyOnLoad - { - get - { - return m_DontDestroyOnLoad; - } - set - { - m_DontDestroyOnLoad = value; - } - } - - public bool runInBackground - { - get - { - return m_RunInBackground; - } - set - { - m_RunInBackground = value; - } - } - - public bool scriptCRCCheck - { - get - { - return m_ScriptCRCCheck; - } - set - { - m_ScriptCRCCheck = value; - } - } - - [Obsolete("moved to NetworkMigrationManager")] - public bool sendPeerInfo - { - get - { - return false; - } - set - { - } - } - - public float maxDelay - { - get - { - return m_MaxDelay; - } - set - { - m_MaxDelay = value; - } - } - - public LogFilter.FilterLevel logLevel - { - get - { - return m_LogLevel; - } - set - { - m_LogLevel = value; - LogFilter.currentLogLevel = (int)value; - } - } - - public GameObject playerPrefab - { - get - { - return m_PlayerPrefab; - } - set - { - m_PlayerPrefab = value; - } - } - - public bool autoCreatePlayer - { - get - { - return m_AutoCreatePlayer; - } - set - { - m_AutoCreatePlayer = value; - } - } - - public PlayerSpawnMethod playerSpawnMethod - { - get - { - return m_PlayerSpawnMethod; - } - set - { - m_PlayerSpawnMethod = value; - } - } - - public string offlineScene - { - get - { - return m_OfflineScene; - } - set - { - m_OfflineScene = value; - } - } - - public string onlineScene - { - get - { - return m_OnlineScene; - } - set - { - m_OnlineScene = value; - } - } - - public List spawnPrefabs - { - get - { - return m_SpawnPrefabs; - } - } + private ConnectionConfig m_ConnectionConfig; + private GlobalConfig m_GlobalConfig; + private int m_MaxBufferedPackets = 16; + private bool m_AllowFragmentation = true; + private static List s_StartPositions = new List(); + private static int s_StartPositionIndex; + private static QSBAddPlayerMessage s_AddPlayerMessage = new QSBAddPlayerMessage(); + private static QSBRemovePlayerMessage s_RemovePlayerMessage = new QSBRemovePlayerMessage(); + private static QSBErrorMessage s_ErrorMessage = new QSBErrorMessage(); + private static AsyncOperation s_LoadingSceneAsync; + private static QSBNetworkConnection s_ClientReadyConnection; + private static string s_Address; public List startPositions { @@ -209,17 +61,7 @@ namespace QuantumUNET } } - public bool customConfig - { - get - { - return m_CustomConfig; - } - set - { - m_CustomConfig = value; - } - } + public bool customConfig { get; set; } public ConnectionConfig connectionConfig { @@ -245,141 +87,17 @@ namespace QuantumUNET } } - public int maxConnections - { - get - { - return m_MaxConnections; - } - set - { - m_MaxConnections = value; - } - } - - public List channels - { - get - { - return m_Channels; - } - } - - public EndPoint secureTunnelEndpoint - { - get - { - return m_EndPoint; - } - set - { - m_EndPoint = value; - } - } - - public bool useWebSockets - { - get - { - return m_UseWebSockets; - } - set - { - m_UseWebSockets = value; - } - } - - public bool useSimulator - { - get - { - return m_UseSimulator; - } - set - { - m_UseSimulator = value; - } - } - - public int simulatedLatency - { - get - { - return m_SimulatedLatency; - } - set - { - m_SimulatedLatency = value; - } - } - - public float packetLossPercentage - { - get - { - return m_PacketLossPercentage; - } - set - { - m_PacketLossPercentage = value; - } - } - - public string matchHost - { - get - { - return m_MatchHost; - } - set - { - m_MatchHost = value; - } - } - - public int matchPort - { - get - { - return m_MatchPort; - } - set - { - m_MatchPort = value; - } - } - - public bool clientLoadedScene - { - get - { - return m_ClientLoadedScene; - } - set - { - m_ClientLoadedScene = value; - } - } - - public QSBNetworkMigrationManager migrationManager - { - get - { - return m_MigrationManager; - } - } - public int numPlayers { get { - int num = 0; - for (int i = 0; i < QSBNetworkServer.connections.Count; i++) + var num = 0; + for (var i = 0; i < QSBNetworkServer.connections.Count; i++) { - QSBNetworkConnection networkConnection = QSBNetworkServer.connections[i]; + var networkConnection = QSBNetworkServer.connections[i]; if (networkConnection != null) { - for (int j = 0; j < networkConnection.PlayerControllers.Count; j++) + for (var j = 0; j < networkConnection.PlayerControllers.Count; j++) { if (networkConnection.PlayerControllers[j].IsValid) { @@ -401,12 +119,7 @@ namespace QuantumUNET { if (!(singleton != null) || !(singleton == this)) { - int logLevel = (int)m_LogLevel; - if (logLevel != -1) - { - LogFilter.currentLogLevel = logLevel; - } - if (m_DontDestroyOnLoad) + if (dontDestroyOnLoad) { if (singleton != null) { @@ -426,80 +139,13 @@ namespace QuantumUNET Debug.Log("NetworkManager created singleton (ForScene)"); singleton = this; } - if (m_NetworkAddress != "") + if (networkAddress != "") { - s_Address = m_NetworkAddress; + s_Address = networkAddress; } else if (s_Address != "") { - m_NetworkAddress = s_Address; - } - } - } - - private void OnValidate() - { - if (m_SimulatedLatency < 1) - { - m_SimulatedLatency = 1; - } - if (m_SimulatedLatency > 500) - { - m_SimulatedLatency = 500; - } - if (m_PacketLossPercentage < 0f) - { - m_PacketLossPercentage = 0f; - } - if (m_PacketLossPercentage > 99f) - { - m_PacketLossPercentage = 99f; - } - if (m_MaxConnections <= 0) - { - m_MaxConnections = 1; - } - if (m_MaxConnections > 32000) - { - m_MaxConnections = 32000; - } - if (m_MaxBufferedPackets <= 0) - { - m_MaxBufferedPackets = 0; - } - if (m_MaxBufferedPackets > 512) - { - m_MaxBufferedPackets = 512; - if (LogFilter.logError) - { - Debug.LogError("NetworkManager - MaxBufferedPackets cannot be more than " + 512); - } - } - if (m_PlayerPrefab != null && m_PlayerPrefab.GetComponent() == null) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); - } - m_PlayerPrefab = null; - } - if (m_ConnectionConfig != null && m_ConnectionConfig.MinUpdateTimeout <= 0U) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkManager MinUpdateTimeout cannot be zero or less. The value will be reset to 1 millisecond"); - } - m_ConnectionConfig.MinUpdateTimeout = 1U; - } - if (m_GlobalConfig != null) - { - if (m_GlobalConfig.ThreadAwakeTimeout <= 0U) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkManager ThreadAwakeTimeout cannot be zero or less. The value will be reset to 1 millisecond"); - } - m_GlobalConfig.ThreadAwakeTimeout = 1U; + networkAddress = s_Address; } } } @@ -514,11 +160,6 @@ namespace QuantumUNET QSBNetworkServer.RegisterHandler(34, new QSBNetworkMessageDelegate(OnServerErrorInternal)); } - public void SetupMigrationManager(QSBNetworkMigrationManager man) - { - m_MigrationManager = man; - } - public bool StartServer(ConnectionConfig config, int maxConnections) { return StartServer(null, config, maxConnections); @@ -538,24 +179,24 @@ namespace QuantumUNET { InitializeSingleton(); OnStartServer(); - if (m_RunInBackground) + if (runInBackground) { Application.runInBackground = true; } QSBNetworkCRC.scriptCRCCheck = scriptCRCCheck; - QSBNetworkServer.useWebSockets = m_UseWebSockets; + QSBNetworkServer.useWebSockets = useWebSockets; if (m_GlobalConfig != null) { NetworkTransport.Init(m_GlobalConfig); } - if (m_CustomConfig && m_ConnectionConfig != null && config == null) + if (customConfig && m_ConnectionConfig != null && config == null) { m_ConnectionConfig.Channels.Clear(); - for (int i = 0; i < m_Channels.Count; i++) + for (var i = 0; i < channels.Count; i++) { - m_ConnectionConfig.AddChannel(m_Channels[i]); + m_ConnectionConfig.AddChannel(channels[i]); } - QSBNetworkServer.Configure(m_ConnectionConfig, m_MaxConnections); + QSBNetworkServer.Configure(m_ConnectionConfig, this.maxConnections); } if (config != null) { @@ -563,7 +204,7 @@ namespace QuantumUNET } if (info != null) { - if (!QSBNetworkServer.Listen(info, m_NetworkPort)) + if (!QSBNetworkServer.Listen(info, networkPort)) { if (LogFilter.logError) { @@ -572,18 +213,18 @@ namespace QuantumUNET return false; } } - else if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress)) + else if (serverBindToIP && !string.IsNullOrEmpty(serverBindAddress)) { - if (!QSBNetworkServer.Listen(m_ServerBindAddress, m_NetworkPort)) + if (!QSBNetworkServer.Listen(serverBindAddress, networkPort)) { if (LogFilter.logError) { - Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed."); + Debug.LogError("StartServer listen on " + serverBindAddress + " failed."); } return false; } } - else if (!QSBNetworkServer.Listen(m_NetworkPort)) + else if (!QSBNetworkServer.Listen(networkPort)) { if (LogFilter.logError) { @@ -594,13 +235,13 @@ namespace QuantumUNET RegisterServerMessages(); if (LogFilter.logDebug) { - Debug.Log("NetworkManager StartServer port:" + m_NetworkPort); + Debug.Log("NetworkManager StartServer port:" + networkPort); } isNetworkActive = true; - string name = SceneManager.GetSceneAt(0).name; - if (!string.IsNullOrEmpty(m_OnlineScene) && m_OnlineScene != name && m_OnlineScene != m_OfflineScene) + var name = SceneManager.GetSceneAt(0).name; + if (!string.IsNullOrEmpty(onlineScene) && onlineScene != name && onlineScene != offlineScene) { - ServerChangeScene(m_OnlineScene); + ServerChangeScene(onlineScene); } else { @@ -616,13 +257,13 @@ namespace QuantumUNET client.RegisterHandler(36, new QSBNetworkMessageDelegate(OnClientNotReadyMessageInternal)); client.RegisterHandler(34, new QSBNetworkMessageDelegate(OnClientErrorInternal)); client.RegisterHandler(39, new QSBNetworkMessageDelegate(OnClientSceneInternal)); - if (m_PlayerPrefab != null) + if (playerPrefab != null) { - QSBClientScene.RegisterPrefab(m_PlayerPrefab); + QSBClientScene.RegisterPrefab(playerPrefab); } - for (int i = 0; i < m_SpawnPrefabs.Count; i++) + for (var i = 0; i < spawnPrefabs.Count; i++) { - GameObject gameObject = m_SpawnPrefabs[i]; + var gameObject = spawnPrefabs[i]; if (gameObject != null) { QSBClientScene.RegisterPrefab(gameObject); @@ -632,7 +273,7 @@ namespace QuantumUNET public void UseExternalClient(QSBNetworkClient externalClient) { - if (m_RunInBackground) + if (runInBackground) { Application.runInBackground = true; } @@ -640,8 +281,8 @@ namespace QuantumUNET { client = externalClient; isNetworkActive = true; - this.RegisterClientMessages(client); - this.OnStartClient(client); + RegisterClientMessages(client); + OnStartClient(client); } else { @@ -649,19 +290,18 @@ namespace QuantumUNET QSBClientScene.DestroyAllClientObjects(); QSBClientScene.HandleClientDisconnect(client.connection); client = null; - if (!string.IsNullOrEmpty(m_OfflineScene)) + if (!string.IsNullOrEmpty(offlineScene)) { - ClientChangeScene(m_OfflineScene, false); + ClientChangeScene(offlineScene, false); } } - s_Address = m_NetworkAddress; + s_Address = networkAddress; } - public QSBNetworkClient StartClient(MatchInfo info, ConnectionConfig config, int hostPort) + public QSBNetworkClient StartClient(ConnectionConfig config, int hostPort) { InitializeSingleton(); - matchInfo = info; - if (m_RunInBackground) + if (runInBackground) { Application.runInBackground = true; } @@ -670,8 +310,10 @@ namespace QuantumUNET { NetworkTransport.Init(m_GlobalConfig); } - client = new QSBNetworkClient(); - client.hostPort = hostPort; + client = new QSBNetworkClient + { + hostPort = hostPort + }; if (config != null) { if (config.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2) @@ -680,77 +322,55 @@ namespace QuantumUNET } client.Configure(config, 1); } - else if (m_CustomConfig && m_ConnectionConfig != null) + else if (customConfig && m_ConnectionConfig != null) { m_ConnectionConfig.Channels.Clear(); - for (int i = 0; i < m_Channels.Count; i++) + for (var i = 0; i < channels.Count; i++) { - m_ConnectionConfig.AddChannel(m_Channels[i]); + m_ConnectionConfig.AddChannel(channels[i]); } if (m_ConnectionConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2) { throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); } - client.Configure(m_ConnectionConfig, m_MaxConnections); + client.Configure(m_ConnectionConfig, maxConnections); } - this.RegisterClientMessages(client); - if (matchInfo != null) + RegisterClientMessages(client); + if (string.IsNullOrEmpty(networkAddress)) { - ModConsole.OwmlConsole.WriteLine("NetworkManager StartClient match: " + matchInfo); - client.Connect(matchInfo); + ModConsole.OwmlConsole.WriteLine("Must set the Network Address field in the manager"); + return null; } - else if (m_EndPoint != null) + ModConsole.OwmlConsole.WriteLine(string.Concat(new object[] { - ModConsole.OwmlConsole.WriteLine("NetworkManager StartClient using provided SecureTunnel"); - client.Connect(m_EndPoint); + "NetworkManager StartClient address:", + networkAddress, + " port:", + networkPort + })); + if (useSimulator) + { + ModConsole.OwmlConsole.WriteLine("connecting with simulator"); + client.ConnectWithSimulator(networkAddress, networkPort, simulatedLatency, packetLossPercentage); } else { - if (string.IsNullOrEmpty(m_NetworkAddress)) - { - ModConsole.OwmlConsole.WriteLine("Must set the Network Address field in the manager"); - return null; - } - ModConsole.OwmlConsole.WriteLine(string.Concat(new object[] - { - "NetworkManager StartClient address:", - m_NetworkAddress, - " port:", - m_NetworkPort - })); - if (m_UseSimulator) - { - ModConsole.OwmlConsole.WriteLine("connecting with simulator"); - client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage); - } - else - { - ModConsole.OwmlConsole.WriteLine("connecting"); - client.Connect(m_NetworkAddress, m_NetworkPort); - } + ModConsole.OwmlConsole.WriteLine("connecting"); + client.Connect(networkAddress, networkPort); } - if (m_MigrationManager != null) - { - m_MigrationManager.Initialize(client, matchInfo); - } - this.OnStartClient(client); - s_Address = m_NetworkAddress; + OnStartClient(client); + s_Address = networkAddress; return client; } - public QSBNetworkClient StartClient(MatchInfo matchInfo) - { - return StartClient(matchInfo, null); - } - public QSBNetworkClient StartClient() { - return StartClient(null, null); + return StartClient(null); } - public QSBNetworkClient StartClient(MatchInfo info, ConnectionConfig config) + public QSBNetworkClient StartClient(ConnectionConfig config) { - return StartClient(info, config, 0); + return StartClient(config, 0); } public virtual QSBNetworkClient StartHost(ConnectionConfig config, int maxConnections) @@ -759,7 +379,7 @@ namespace QuantumUNET QSBNetworkClient result; if (StartServer(config, maxConnections)) { - QSBNetworkClient networkClient = ConnectLocalClient(); + var networkClient = ConnectLocalClient(); OnServerConnect(networkClient.connection); OnStartClient(networkClient); result = networkClient; @@ -774,11 +394,10 @@ namespace QuantumUNET public virtual QSBNetworkClient StartHost(MatchInfo info) { OnStartHost(); - matchInfo = info; QSBNetworkClient result; if (StartServer(info)) { - QSBNetworkClient networkClient = ConnectLocalClient(); + var networkClient = ConnectLocalClient(); OnStartClient(networkClient); result = networkClient; } @@ -795,7 +414,7 @@ namespace QuantumUNET QSBNetworkClient result; if (StartServer()) { - QSBNetworkClient networkClient = ConnectLocalClient(); + var networkClient = ConnectLocalClient(); OnStartClient(networkClient); result = networkClient; } @@ -810,31 +429,19 @@ namespace QuantumUNET { if (LogFilter.logDebug) { - Debug.Log("NetworkManager StartHost port:" + m_NetworkPort); + Debug.Log("NetworkManager StartHost port:" + networkPort); } - m_NetworkAddress = "localhost"; + networkAddress = "localhost"; client = QSBClientScene.ConnectLocalServer(); - this.RegisterClientMessages(client); - if (m_MigrationManager != null) - { - m_MigrationManager.Initialize(client, matchInfo); - } + RegisterClientMessages(client); return client; } public void StopHost() { - bool active = QSBNetworkServer.active; OnStopHost(); StopServer(); StopClient(); - if (m_MigrationManager != null) - { - if (active) - { - m_MigrationManager.LostHostOnHost(); - } - } } public void StopServer() @@ -848,10 +455,10 @@ namespace QuantumUNET } isNetworkActive = false; QSBNetworkServer.Shutdown(); - StopMatchMaker(); - if (!string.IsNullOrEmpty(m_OfflineScene)) + //StopMatchMaker(); + if (!string.IsNullOrEmpty(offlineScene)) { - ServerChangeScene(m_OfflineScene); + ServerChangeScene(offlineScene); } CleanupNetworkIdentities(); } @@ -871,11 +478,11 @@ namespace QuantumUNET client.Shutdown(); client = null; } - StopMatchMaker(); + //StopMatchMaker(); QSBClientScene.DestroyAllClientObjects(); - if (!string.IsNullOrEmpty(m_OfflineScene)) + if (!string.IsNullOrEmpty(offlineScene)) { - ClientChangeScene(m_OfflineScene, false); + ClientChangeScene(offlineScene, false); } CleanupNetworkIdentities(); } @@ -898,7 +505,7 @@ namespace QuantumUNET QSBNetworkServer.SetAllClientsNotReady(); networkSceneName = newSceneName; s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName); - QSBStringMessage msg = new QSBStringMessage(networkSceneName); + var msg = new QSBStringMessage(networkSceneName); QSBNetworkServer.SendToAll(39, msg); s_StartPositionIndex = 0; s_StartPositions.Clear(); @@ -907,7 +514,7 @@ namespace QuantumUNET private void CleanupNetworkIdentities() { - foreach (QSBNetworkIdentity networkIdentity in Resources.FindObjectsOfTypeAll()) + foreach (var networkIdentity in Resources.FindObjectsOfTypeAll()) { networkIdentity.MarkForReset(); } @@ -930,11 +537,6 @@ namespace QuantumUNET } if (newSceneName == networkSceneName) { - if (m_MigrationManager != null) - { - FinishLoadScene(); - return; - } if (!forceReload) { FinishLoadScene(); @@ -952,8 +554,8 @@ namespace QuantumUNET { if (s_ClientReadyConnection != null) { - m_ClientLoadedScene = true; - this.OnClientConnect(s_ClientReadyConnection); + clientLoadedScene = true; + OnClientConnect(s_ClientReadyConnection); s_ClientReadyConnection = null; } } @@ -968,8 +570,8 @@ namespace QuantumUNET } if (IsClientConnected() && client != null) { - this.RegisterClientMessages(client); - this.OnClientSceneChanged(client.connection); + RegisterClientMessages(client); + OnClientSceneChanged(client.connection); } } @@ -990,11 +592,6 @@ namespace QuantumUNET } } - private void OnDestroy() - { - Debug.Log("NetworkManager destroyed"); - } - public static void RegisterStartPosition(Transform start) { if (LogFilter.logDebug) @@ -1048,30 +645,26 @@ namespace QuantumUNET { Debug.Log("NetworkManager:OnServerConnectInternal"); } - netMsg.Connection.SetMaxDelay(m_MaxDelay); + netMsg.Connection.SetMaxDelay(maxDelay); if (m_MaxBufferedPackets != 512) { - for (int i = 0; i < QSBNetworkServer.numChannels; i++) + for (var i = 0; i < QSBNetworkServer.numChannels; i++) { netMsg.Connection.SetChannelOption(i, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets); } } if (!m_AllowFragmentation) { - for (int j = 0; j < QSBNetworkServer.numChannels; j++) + for (var j = 0; j < QSBNetworkServer.numChannels; j++) { netMsg.Connection.SetChannelOption(j, ChannelOption.AllowFragmentation, 0); } } - if (networkSceneName != "" && networkSceneName != m_OfflineScene) + if (networkSceneName != "" && networkSceneName != offlineScene) { - QSBStringMessage msg = new QSBStringMessage(networkSceneName); + var msg = new QSBStringMessage(networkSceneName); netMsg.Connection.Send(39, msg); } - if (m_MigrationManager != null) - { - m_MigrationManager.SendPeerInfo(); - } OnServerConnect(netMsg.Connection); } @@ -1081,10 +674,6 @@ namespace QuantumUNET { Debug.Log("NetworkManager:OnServerDisconnectInternal"); } - if (m_MigrationManager != null) - { - m_MigrationManager.SendPeerInfo(); - } OnServerDisconnect(netMsg.Connection); } @@ -1106,16 +695,12 @@ namespace QuantumUNET netMsg.ReadMessage(s_AddPlayerMessage); if (s_AddPlayerMessage.msgSize != 0) { - NetworkReader extraMessageReader = new NetworkReader(s_AddPlayerMessage.msgData); - this.OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId, extraMessageReader); + var extraMessageReader = new NetworkReader(s_AddPlayerMessage.msgData); + OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId, extraMessageReader); } else { - this.OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId); - } - if (m_MigrationManager != null) - { - m_MigrationManager.SendPeerInfo(); + OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId); } } @@ -1126,14 +711,9 @@ namespace QuantumUNET Debug.Log("NetworkManager:OnServerRemovePlayerMessageInternal"); } netMsg.ReadMessage(s_RemovePlayerMessage); - QSBPlayerController player; - netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out player); + netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out var player); OnServerRemovePlayer(netMsg.Connection, player); netMsg.Connection.RemovePlayerController(s_RemovePlayerMessage.PlayerControllerId); - if (m_MigrationManager != null) - { - m_MigrationManager.SendPeerInfo(); - } } internal void OnServerErrorInternal(QSBNetworkMessage netMsg) @@ -1143,7 +723,7 @@ namespace QuantumUNET Debug.Log("NetworkManager:OnServerErrorInternal"); } netMsg.ReadMessage(s_ErrorMessage); - this.OnServerError(netMsg.Connection, s_ErrorMessage.errorCode); + OnServerError(netMsg.Connection, s_ErrorMessage.errorCode); } internal void OnClientConnectInternal(QSBNetworkMessage netMsg) @@ -1152,11 +732,11 @@ namespace QuantumUNET { Debug.Log("NetworkManager:OnClientConnectInternal"); } - netMsg.Connection.SetMaxDelay(m_MaxDelay); - string name = SceneManager.GetSceneAt(0).name; - if (string.IsNullOrEmpty(m_OnlineScene) || m_OnlineScene == m_OfflineScene || name == m_OnlineScene) + netMsg.Connection.SetMaxDelay(maxDelay); + var name = SceneManager.GetSceneAt(0).name; + if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene) { - m_ClientLoadedScene = false; + clientLoadedScene = false; OnClientConnect(netMsg.Connection); } else @@ -1171,20 +751,9 @@ namespace QuantumUNET { Debug.Log("NetworkManager:OnClientDisconnectInternal"); } - if (m_MigrationManager != null) + if (!string.IsNullOrEmpty(offlineScene)) { - if (m_MigrationManager.LostHostOnClient(netMsg.Connection)) - { - return; - } - } - if (!string.IsNullOrEmpty(m_OfflineScene)) - { - ClientChangeScene(m_OfflineScene, false); - } - if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != NodeID.Invalid) - { - matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, new NetworkMatch.BasicResponseDelegate(OnDropConnection)); + ClientChangeScene(offlineScene, false); } OnClientDisconnect(netMsg.Connection); } @@ -1206,7 +775,7 @@ namespace QuantumUNET Debug.Log("NetworkManager:OnClientErrorInternal"); } netMsg.ReadMessage(s_ErrorMessage); - this.OnClientError(netMsg.Connection, s_ErrorMessage.errorCode); + OnClientError(netMsg.Connection, s_ErrorMessage.errorCode); } internal void OnClientSceneInternal(QSBNetworkMessage netMsg) @@ -1215,7 +784,7 @@ namespace QuantumUNET { Debug.Log("NetworkManager:OnClientSceneInternal"); } - string newSceneName = netMsg.Reader.ReadString(); + var newSceneName = netMsg.Reader.ReadString(); if (IsClientConnected() && !QSBNetworkServer.active) { ClientChangeScene(newSceneName, true); @@ -1262,21 +831,21 @@ namespace QuantumUNET private void OnServerAddPlayerInternal(QSBNetworkConnection conn, short playerControllerId) { - if (m_PlayerPrefab == null) + if (playerPrefab == null) { if (LogFilter.logError) { ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object."); } } - else if (m_PlayerPrefab.GetComponent() == null) + else if (playerPrefab.GetComponent() == null) { if (LogFilter.logError) { ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab."); } } - else if ((int)playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[(int)playerControllerId].IsValid && conn.PlayerControllers[(int)playerControllerId].Gameobject != null) + else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null) { if (LogFilter.logError) { @@ -1285,15 +854,15 @@ namespace QuantumUNET } else { - Transform startPosition = GetStartPosition(); + var startPosition = GetStartPosition(); GameObject player; if (startPosition != null) { - player = Instantiate(m_PlayerPrefab, startPosition.position, startPosition.rotation); + player = Instantiate(playerPrefab, startPosition.position, startPosition.rotation); } else { - player = Instantiate(m_PlayerPrefab, Vector3.zero, Quaternion.identity); + player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); } QSBNetworkServer.AddPlayerForConnection(conn, player, playerControllerId); } @@ -1303,7 +872,7 @@ namespace QuantumUNET { if (s_StartPositions.Count > 0) { - for (int i = s_StartPositions.Count - 1; i >= 0; i--) + for (var i = s_StartPositions.Count - 1; i >= 0; i--) { if (s_StartPositions[i] == null) { @@ -1312,18 +881,18 @@ namespace QuantumUNET } } Transform result; - if (m_PlayerSpawnMethod == PlayerSpawnMethod.Random && s_StartPositions.Count > 0) + if (playerSpawnMethod == PlayerSpawnMethod.Random && s_StartPositions.Count > 0) { - int index = UnityEngine.Random.Range(0, s_StartPositions.Count); + var index = UnityEngine.Random.Range(0, s_StartPositions.Count); result = s_StartPositions[index]; } - else if (m_PlayerSpawnMethod == PlayerSpawnMethod.RoundRobin && s_StartPositions.Count > 0) + else if (playerSpawnMethod == PlayerSpawnMethod.RoundRobin && s_StartPositions.Count > 0) { if (s_StartPositionIndex >= s_StartPositions.Count) { s_StartPositionIndex = 0; } - Transform transform = s_StartPositions[s_StartPositionIndex]; + var transform = s_StartPositions[s_StartPositionIndex]; s_StartPositionIndex++; result = transform; } @@ -1355,7 +924,7 @@ namespace QuantumUNET if (!clientLoadedScene) { QSBClientScene.Ready(conn); - if (m_AutoCreatePlayer) + if (autoCreatePlayer) { QSBClientScene.AddPlayer(0); } @@ -1385,11 +954,11 @@ namespace QuantumUNET public virtual void OnClientSceneChanged(QSBNetworkConnection conn) { QSBClientScene.Ready(conn); - if (m_AutoCreatePlayer) + if (autoCreatePlayer) { - bool flag = QSBClientScene.localPlayers.Count == 0; - bool flag2 = false; - for (int i = 0; i < QSBClientScene.localPlayers.Count; i++) + var flag = QSBClientScene.localPlayers.Count == 0; + var flag2 = false; + for (var i = 0; i < QSBClientScene.localPlayers.Count; i++) { if (QSBClientScene.localPlayers[i].Gameobject != null) { @@ -1408,69 +977,6 @@ namespace QuantumUNET } } - public void StartMatchMaker() - { - if (LogFilter.logDebug) - { - Debug.Log("NetworkManager StartMatchMaker"); - } - SetMatchHost(m_MatchHost, m_MatchPort, m_MatchPort == 443); - } - - public void StopMatchMaker() - { - if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != NodeID.Invalid) - { - matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, new NetworkMatch.BasicResponseDelegate(OnDropConnection)); - } - if (matchMaker != null) - { - Destroy(matchMaker); - matchMaker = null; - } - matchInfo = null; - matches = null; - } - - public void SetMatchHost(string newHost, int port, bool https) - { - if (matchMaker == null) - { - matchMaker = base.gameObject.AddComponent(); - } - if (newHost == "127.0.0.1") - { - newHost = "localhost"; - } - string text = "http://"; - if (https) - { - text = "https://"; - } - if (newHost.StartsWith("http://")) - { - newHost = newHost.Replace("http://", ""); - } - if (newHost.StartsWith("https://")) - { - newHost = newHost.Replace("https://", ""); - } - m_MatchHost = newHost; - m_MatchPort = port; - string text2 = string.Concat(new object[] - { - text, - m_MatchHost, - ":", - m_MatchPort - }); - if (LogFilter.logDebug) - { - Debug.Log("SetMatchHost:" + text2); - } - matchMaker.baseUri = new Uri(text2); - } - public virtual void OnStartHost() { } @@ -1494,215 +1000,5 @@ namespace QuantumUNET public virtual void OnStopHost() { } - - public virtual void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnMatchCreate Success:{0}, ExtendedInfo:{1}, matchInfo:{2}", new object[] - { - success, - extendedInfo, - matchInfo - }); - } - if (success) - { - StartHost(matchInfo); - } - } - - public virtual void OnMatchList(bool success, string extendedInfo, List matchList) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnMatchList Success:{0}, ExtendedInfo:{1}, matchList.Count:{2}", new object[] - { - success, - extendedInfo, - matchList.Count - }); - } - matches = matchList; - } - - public virtual void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnMatchJoined Success:{0}, ExtendedInfo:{1}, matchInfo:{2}", new object[] - { - success, - extendedInfo, - matchInfo - }); - } - if (success) - { - StartClient(matchInfo); - } - } - - public virtual void OnDestroyMatch(bool success, string extendedInfo) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnDestroyMatch Success:{0}, ExtendedInfo:{1}", new object[] - { - success, - extendedInfo - }); - } - } - - public virtual void OnDropConnection(bool success, string extendedInfo) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnDropConnection Success:{0}, ExtendedInfo:{1}", new object[] - { - success, - extendedInfo - }); - } - } - - public virtual void OnSetMatchAttributes(bool success, string extendedInfo) - { - if (LogFilter.logDebug) - { - Debug.LogFormat("NetworkManager OnSetMatchAttributes Success:{0}, ExtendedInfo:{1}", new object[] - { - success, - extendedInfo - }); - } - } - - [SerializeField] - private int m_NetworkPort = 7777; - - [SerializeField] - private bool m_ServerBindToIP; - - [SerializeField] - private string m_ServerBindAddress = ""; - - [SerializeField] - private string m_NetworkAddress = "localhost"; - - [SerializeField] - private bool m_DontDestroyOnLoad = true; - - [SerializeField] - private bool m_RunInBackground = true; - - [SerializeField] - private bool m_ScriptCRCCheck = true; - - [SerializeField] - private float m_MaxDelay = 0.01f; - - [SerializeField] - private LogFilter.FilterLevel m_LogLevel = LogFilter.FilterLevel.Info; - - [SerializeField] - private GameObject m_PlayerPrefab; - - [SerializeField] - private bool m_AutoCreatePlayer = true; - - [SerializeField] - private PlayerSpawnMethod m_PlayerSpawnMethod; - - [SerializeField] - private string m_OfflineScene = ""; - - [SerializeField] - private string m_OnlineScene = ""; - - [SerializeField] - private List m_SpawnPrefabs = new List(); - - [SerializeField] - private bool m_CustomConfig; - - [SerializeField] - private int m_MaxConnections = 4; - - [SerializeField] - private ConnectionConfig m_ConnectionConfig; - - [SerializeField] - private GlobalConfig m_GlobalConfig; - - [SerializeField] - private List m_Channels = new List(); - - [SerializeField] - private bool m_UseWebSockets; - - [SerializeField] - private bool m_UseSimulator; - - [SerializeField] - private int m_SimulatedLatency = 1; - - [SerializeField] - private float m_PacketLossPercentage; - - [SerializeField] - private int m_MaxBufferedPackets = 16; - - [SerializeField] - private bool m_AllowFragmentation = true; - - [SerializeField] - private string m_MatchHost = "mm.unet.unity3d.com"; - - [SerializeField] - private int m_MatchPort = 443; - - [SerializeField] - public string matchName = "default"; - - [SerializeField] - public uint matchSize = 4U; - - private QSBNetworkMigrationManager m_MigrationManager; - - private EndPoint m_EndPoint; - - private bool m_ClientLoadedScene; - - public static string networkSceneName = ""; - - public bool isNetworkActive; - - public QSBNetworkClient client; - - private static List s_StartPositions = new List(); - - private static int s_StartPositionIndex; - - public MatchInfo matchInfo; - - public NetworkMatch matchMaker; - - public List matches; - - public static QSBNetworkManagerUNET singleton; - - private static QSBAddPlayerMessage s_AddPlayerMessage = new QSBAddPlayerMessage(); - - private static QSBRemovePlayerMessage s_RemovePlayerMessage = new QSBRemovePlayerMessage(); - - private static QSBErrorMessage s_ErrorMessage = new QSBErrorMessage(); - - private static AsyncOperation s_LoadingSceneAsync; - - private static QSBNetworkConnection s_ClientReadyConnection; - - private static string s_Address; } } \ No newline at end of file diff --git a/QuantumUNET/QSBNetworkMigrationManager.cs b/QuantumUNET/QSBNetworkMigrationManager.cs deleted file mode 100644 index 5af90dc9..00000000 --- a/QuantumUNET/QSBNetworkMigrationManager.cs +++ /dev/null @@ -1,1066 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Networking; -using UnityEngine.Networking.Match; -using UnityEngine.Networking.Types; - -namespace QuantumUNET -{ - public class QSBNetworkMigrationManager : MonoBehaviour - { - private void AddPendingPlayer(GameObject obj, int connectionId, NetworkInstanceId netId, short playerControllerId) - { - if (!this.m_PendingPlayers.ContainsKey(connectionId)) - { - ConnectionPendingPlayers value = default(ConnectionPendingPlayers); - value.players = new List(); - this.m_PendingPlayers[connectionId] = value; - } - PendingPlayerInfo item = default(PendingPlayerInfo); - item.netId = netId; - item.playerControllerId = playerControllerId; - item.obj = obj; - this.m_PendingPlayers[connectionId].players.Add(item); - } - - private GameObject FindPendingPlayer(int connectionId, NetworkInstanceId netId, short playerControllerId) - { - if (this.m_PendingPlayers.ContainsKey(connectionId)) - { - for (int i = 0; i < this.m_PendingPlayers[connectionId].players.Count; i++) - { - PendingPlayerInfo pendingPlayerInfo = this.m_PendingPlayers[connectionId].players[i]; - if (pendingPlayerInfo.netId == netId && pendingPlayerInfo.playerControllerId == playerControllerId) - { - return pendingPlayerInfo.obj; - } - } - } - return null; - } - - private void RemovePendingPlayer(int connectionId) - { - this.m_PendingPlayers.Remove(connectionId); - } - - public bool hostMigration - { - get - { - return this.m_HostMigration; - } - set - { - this.m_HostMigration = value; - } - } - - public bool showGUI - { - get - { - return this.m_ShowGUI; - } - set - { - this.m_ShowGUI = value; - } - } - - public int offsetX - { - get - { - return this.m_OffsetX; - } - set - { - this.m_OffsetX = value; - } - } - - public int offsetY - { - get - { - return this.m_OffsetY; - } - set - { - this.m_OffsetY = value; - } - } - - public QSBNetworkClient client - { - get - { - return this.m_Client; - } - } - - public bool waitingToBecomeNewHost - { - get - { - return this.m_WaitingToBecomeNewHost; - } - set - { - this.m_WaitingToBecomeNewHost = value; - } - } - - public bool waitingReconnectToNewHost - { - get - { - return this.m_WaitingReconnectToNewHost; - } - set - { - this.m_WaitingReconnectToNewHost = value; - } - } - - public bool disconnectedFromHost - { - get - { - return this.m_DisconnectedFromHost; - } - } - - public bool hostWasShutdown - { - get - { - return this.m_HostWasShutdown; - } - } - - public MatchInfo matchInfo - { - get - { - return this.m_MatchInfo; - } - } - - public int oldServerConnectionId - { - get - { - return this.m_OldServerConnectionId; - } - } - - public string newHostAddress - { - get - { - return this.m_NewHostAddress; - } - set - { - this.m_NewHostAddress = value; - } - } - - public QSBPeerInfoMessage[] peers - { - get - { - return this.m_Peers; - } - } - - public Dictionary pendingPlayers - { - get - { - return this.m_PendingPlayers; - } - } - - private void Start() - { - this.Reset(-1); - } - - public void Reset(int reconnectId) - { - this.m_OldServerConnectionId = -1; - this.m_WaitingToBecomeNewHost = false; - this.m_WaitingReconnectToNewHost = false; - this.m_DisconnectedFromHost = false; - this.m_HostWasShutdown = false; - QSBClientScene.SetReconnectId(reconnectId, this.m_Peers); - if (QSBNetworkManagerUNET.singleton != null) - { - QSBNetworkManagerUNET.singleton.SetupMigrationManager(this); - } - } - - internal void AssignAuthorityCallback(QSBNetworkConnection conn, QSBNetworkIdentity uv, bool authorityState) - { - QSBPeerAuthorityMessage peerAuthorityMessage = new QSBPeerAuthorityMessage(); - peerAuthorityMessage.connectionId = conn.connectionId; - peerAuthorityMessage.netId = uv.NetId; - peerAuthorityMessage.authorityState = authorityState; - if (LogFilter.logDebug) - { - Debug.Log("AssignAuthorityCallback send for netId" + uv.NetId); - } - for (int i = 0; i < QSBNetworkServer.connections.Count; i++) - { - QSBNetworkConnection networkConnection = QSBNetworkServer.connections[i]; - if (networkConnection != null) - { - networkConnection.Send(18, peerAuthorityMessage); - } - } - } - - public void Initialize(QSBNetworkClient newClient, MatchInfo newMatchInfo) - { - Debug.Log("NetworkMigrationManager initialize"); - this.m_Client = newClient; - this.m_MatchInfo = newMatchInfo; - newClient.RegisterHandlerSafe(11, new QSBNetworkMessageDelegate(this.OnPeerInfo)); - newClient.RegisterHandlerSafe(18, new QSBNetworkMessageDelegate(this.OnPeerClientAuthority)); - QSBNetworkIdentity.clientAuthorityCallback = new QSBNetworkIdentity.ClientAuthorityCallback(this.AssignAuthorityCallback); - } - - public void DisablePlayerObjects() - { - Debug.Log("NetworkMigrationManager DisablePlayerObjects"); - if (this.m_Peers != null) - { - for (int i = 0; i < this.m_Peers.Length; i++) - { - QSBPeerInfoMessage peerInfoMessage = this.m_Peers[i]; - if (peerInfoMessage.playerIds != null) - { - for (int j = 0; j < peerInfoMessage.playerIds.Length; j++) - { - QSBPeerInfoPlayer peerInfoPlayer = peerInfoMessage.playerIds[j]; - Debug.Log(string.Concat(new object[] - { - "DisablePlayerObjects disable player for ", - peerInfoMessage.address, - " netId:", - peerInfoPlayer.netId, - " control:", - peerInfoPlayer.playerControllerId - })); - GameObject gameObject = QSBClientScene.FindLocalObject(peerInfoPlayer.netId); - if (gameObject != null) - { - gameObject.SetActive(false); - this.AddPendingPlayer(gameObject, peerInfoMessage.connectionId, peerInfoPlayer.netId, peerInfoPlayer.playerControllerId); - } - else if (LogFilter.logWarn) - { - Debug.LogWarning(string.Concat(new object[] - { - "DisablePlayerObjects didnt find player Conn:", - peerInfoMessage.connectionId, - " NetId:", - peerInfoPlayer.netId - })); - } - } - } - } - } - } - - public void SendPeerInfo() - { - if (this.m_HostMigration) - { - QSBPeerListMessage peerListMessage = new QSBPeerListMessage(); - List list = new List(); - for (int i = 0; i < QSBNetworkServer.connections.Count; i++) - { - QSBNetworkConnection networkConnection = QSBNetworkServer.connections[i]; - if (networkConnection != null) - { - QSBPeerInfoMessage peerInfoMessage = new QSBPeerInfoMessage(); - string address; - int port; - NetworkID networkID; - NodeID nodeID; - byte b; - NetworkTransport.GetConnectionInfo(QSBNetworkServer.serverHostId, networkConnection.connectionId, out address, out port, out networkID, out nodeID, out b); - peerInfoMessage.connectionId = networkConnection.connectionId; - peerInfoMessage.port = port; - if (i == 0) - { - peerInfoMessage.port = QSBNetworkServer.listenPort; - peerInfoMessage.isHost = true; - peerInfoMessage.address = ""; - } - else - { - peerInfoMessage.address = address; - peerInfoMessage.isHost = false; - } - List list2 = new List(); - for (int j = 0; j < networkConnection.PlayerControllers.Count; j++) - { - QSBPlayerController playerController = networkConnection.PlayerControllers[j]; - if (playerController != null && playerController.UnetView != null) - { - QSBPeerInfoPlayer item; - item.netId = playerController.UnetView.NetId; - item.playerControllerId = playerController.UnetView.PlayerControllerId; - list2.Add(item); - } - } - if (networkConnection.ClientOwnedObjects != null) - { - foreach (NetworkInstanceId netId in networkConnection.ClientOwnedObjects) - { - GameObject gameObject = QSBNetworkServer.FindLocalObject(netId); - if (!(gameObject == null)) - { - QSBNetworkIdentity component = gameObject.GetComponent(); - if (component.PlayerControllerId == -1) - { - QSBPeerInfoPlayer item2; - item2.netId = netId; - item2.playerControllerId = -1; - list2.Add(item2); - } - } - } - } - if (list2.Count > 0) - { - peerInfoMessage.playerIds = list2.ToArray(); - } - list.Add(peerInfoMessage); - } - } - peerListMessage.peers = list.ToArray(); - for (int k = 0; k < QSBNetworkServer.connections.Count; k++) - { - QSBNetworkConnection networkConnection2 = QSBNetworkServer.connections[k]; - if (networkConnection2 != null) - { - peerListMessage.oldServerConnectionId = networkConnection2.connectionId; - networkConnection2.Send(11, peerListMessage); - } - } - } - } - - private void OnPeerClientAuthority(QSBNetworkMessage netMsg) - { - QSBPeerAuthorityMessage peerAuthorityMessage = netMsg.ReadMessage(); - if (LogFilter.logDebug) - { - Debug.Log("OnPeerClientAuthority for netId:" + peerAuthorityMessage.netId); - } - if (this.m_Peers != null) - { - for (int i = 0; i < this.m_Peers.Length; i++) - { - QSBPeerInfoMessage peerInfoMessage = this.m_Peers[i]; - if (peerInfoMessage.connectionId == peerAuthorityMessage.connectionId) - { - if (peerInfoMessage.playerIds == null) - { - peerInfoMessage.playerIds = new QSBPeerInfoPlayer[0]; - } - if (peerAuthorityMessage.authorityState) - { - for (int j = 0; j < peerInfoMessage.playerIds.Length; j++) - { - if (peerInfoMessage.playerIds[j].netId == peerAuthorityMessage.netId) - { - return; - } - } - QSBPeerInfoPlayer item = default(QSBPeerInfoPlayer); - item.netId = peerAuthorityMessage.netId; - item.playerControllerId = -1; - peerInfoMessage.playerIds = new List(peerInfoMessage.playerIds) - { - item - }.ToArray(); - } - else - { - for (int k = 0; k < peerInfoMessage.playerIds.Length; k++) - { - if (peerInfoMessage.playerIds[k].netId == peerAuthorityMessage.netId) - { - List list = new List(peerInfoMessage.playerIds); - list.RemoveAt(k); - peerInfoMessage.playerIds = list.ToArray(); - break; - } - } - } - } - } - GameObject go = QSBClientScene.FindLocalObject(peerAuthorityMessage.netId); - this.OnAuthorityUpdated(go, peerAuthorityMessage.connectionId, peerAuthorityMessage.authorityState); - } - } - - private void OnPeerInfo(QSBNetworkMessage netMsg) - { - if (LogFilter.logDebug) - { - Debug.Log("OnPeerInfo"); - } - netMsg.ReadMessage(this.m_PeerListMessage); - this.m_Peers = this.m_PeerListMessage.peers; - this.m_OldServerConnectionId = this.m_PeerListMessage.oldServerConnectionId; - for (int i = 0; i < this.m_Peers.Length; i++) - { - if (LogFilter.logDebug) - { - Debug.Log(string.Concat(new object[] - { - "peer conn ", - this.m_Peers[i].connectionId, - " your conn ", - this.m_PeerListMessage.oldServerConnectionId - })); - } - if (this.m_Peers[i].connectionId == this.m_PeerListMessage.oldServerConnectionId) - { - this.m_Peers[i].isYou = true; - break; - } - } - this.OnPeersUpdated(this.m_PeerListMessage); - } - - private void OnServerReconnectPlayerMessage(QSBNetworkMessage netMsg) - { - QSBReconnectMessage reconnectMessage = netMsg.ReadMessage(); - Debug.Log(string.Concat(new object[] - { - "OnReconnectMessage: connId=", - reconnectMessage.oldConnectionId, - " playerControllerId:", - reconnectMessage.playerControllerId, - " netId:", - reconnectMessage.netId - })); - GameObject gameObject = this.FindPendingPlayer(reconnectMessage.oldConnectionId, reconnectMessage.netId, reconnectMessage.playerControllerId); - if (gameObject == null) - { - if (LogFilter.logError) - { - Debug.LogError(string.Concat(new object[] - { - "OnReconnectMessage connId=", - reconnectMessage.oldConnectionId, - " player null for netId:", - reconnectMessage.netId, - " msg.playerControllerId:", - reconnectMessage.playerControllerId - })); - } - } - else if (gameObject.activeSelf) - { - if (LogFilter.logError) - { - Debug.LogError("OnReconnectMessage connId=" + reconnectMessage.oldConnectionId + " player already active?"); - } - } - else - { - if (LogFilter.logDebug) - { - Debug.Log("OnReconnectMessage: player=" + gameObject); - } - NetworkReader networkReader = null; - if (reconnectMessage.msgSize != 0) - { - networkReader = new NetworkReader(reconnectMessage.msgData); - } - if (reconnectMessage.playerControllerId != -1) - { - if (networkReader == null) - { - this.OnServerReconnectPlayer(netMsg.Connection, gameObject, reconnectMessage.oldConnectionId, reconnectMessage.playerControllerId); - } - else - { - this.OnServerReconnectPlayer(netMsg.Connection, gameObject, reconnectMessage.oldConnectionId, reconnectMessage.playerControllerId, networkReader); - } - } - else - { - this.OnServerReconnectObject(netMsg.Connection, gameObject, reconnectMessage.oldConnectionId); - } - } - } - - public bool ReconnectObjectForConnection(QSBNetworkConnection newConnection, GameObject oldObject, int oldConnectionId) - { - bool result; - if (!QSBNetworkServer.active) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectObjectForConnection must have active server"); - } - result = false; - } - else - { - if (LogFilter.logDebug) - { - Debug.Log(string.Concat(new object[] - { - "ReconnectObjectForConnection: oldConnId=", - oldConnectionId, - " obj=", - oldObject, - " conn:", - newConnection - })); - } - if (!this.m_PendingPlayers.ContainsKey(oldConnectionId)) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " not found."); - } - result = false; - } - else - { - oldObject.SetActive(true); - oldObject.GetComponent().SetNetworkInstanceId(new NetworkInstanceId(0U)); - if (!QSBNetworkServer.SpawnWithClientAuthority(oldObject, newConnection)) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " SpawnWithClientAuthority failed."); - } - result = false; - } - else - { - result = true; - } - } - } - return result; - } - - public bool ReconnectPlayerForConnection(QSBNetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId) - { - bool result; - if (!QSBNetworkServer.active) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectPlayerForConnection must have active server"); - } - result = false; - } - else - { - if (LogFilter.logDebug) - { - Debug.Log(string.Concat(new object[] - { - "ReconnectPlayerForConnection: oldConnId=", - oldConnectionId, - " player=", - oldPlayer, - " conn:", - newConnection - })); - } - if (!this.m_PendingPlayers.ContainsKey(oldConnectionId)) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " not found."); - } - result = false; - } - else - { - oldPlayer.SetActive(true); - QSBNetworkServer.Spawn(oldPlayer); - if (!QSBNetworkServer.AddPlayerForConnection(newConnection, oldPlayer, playerControllerId)) - { - if (LogFilter.logError) - { - Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " AddPlayerForConnection failed."); - } - result = false; - } - else - { - if (QSBNetworkServer.localClientActive) - { - this.SendPeerInfo(); - } - result = true; - } - } - } - return result; - } - - public bool LostHostOnClient(QSBNetworkConnection conn) - { - if (LogFilter.logDebug) - { - Debug.Log("NetworkMigrationManager client OnDisconnectedFromHost"); - } - bool result; - if (Application.platform == RuntimePlatform.WebGLPlayer) - { - if (LogFilter.logError) - { - Debug.LogError("LostHostOnClient: Host migration not supported on WebGL"); - } - result = false; - } - else if (this.m_Client == null) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkMigrationManager LostHostOnHost client was never initialized."); - } - result = false; - } - else if (!this.m_HostMigration) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkMigrationManager LostHostOnHost migration not enabled."); - } - result = false; - } - else - { - this.m_DisconnectedFromHost = true; - this.DisablePlayerObjects(); - byte b; - NetworkTransport.Disconnect(this.m_Client.hostId, this.m_Client.connection.connectionId, out b); - if (this.m_OldServerConnectionId != -1) - { - SceneChangeOption sceneChangeOption; - this.OnClientDisconnectedFromHost(conn, out sceneChangeOption); - result = (sceneChangeOption == SceneChangeOption.StayInOnlineScene); - } - else - { - result = false; - } - } - return result; - } - - public void LostHostOnHost() - { - if (LogFilter.logDebug) - { - Debug.Log("NetworkMigrationManager LostHostOnHost"); - } - if (Application.platform == RuntimePlatform.WebGLPlayer) - { - if (LogFilter.logError) - { - Debug.LogError("LostHostOnHost: Host migration not supported on WebGL"); - } - } - else - { - this.OnServerHostShutdown(); - if (this.m_Peers == null) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkMigrationManager LostHostOnHost no peers"); - } - } - else if (this.m_Peers.Length != 1) - { - this.m_HostWasShutdown = true; - } - } - } - - public bool BecomeNewHost(int port) - { - if (LogFilter.logDebug) - { - Debug.Log("NetworkMigrationManager BecomeNewHost " + this.m_MatchInfo); - } - QSBNetworkServer.RegisterHandler(47, new QSBNetworkMessageDelegate(this.OnServerReconnectPlayerMessage)); - QSBNetworkClient networkClient = QSBNetworkServer.BecomeHost(this.m_Client, port, this.m_MatchInfo, this.oldServerConnectionId, this.peers); - bool result; - if (networkClient != null) - { - if (QSBNetworkManagerUNET.singleton != null) - { - QSBNetworkManagerUNET.singleton.RegisterServerMessages(); - QSBNetworkManagerUNET.singleton.UseExternalClient(networkClient); - } - else - { - Debug.LogWarning("MigrationManager BecomeNewHost - No NetworkManager."); - } - networkClient.RegisterHandlerSafe(11, new QSBNetworkMessageDelegate(this.OnPeerInfo)); - this.RemovePendingPlayer(this.m_OldServerConnectionId); - this.Reset(-1); - this.SendPeerInfo(); - result = true; - } - else - { - if (LogFilter.logError) - { - Debug.LogError("NetworkServer.BecomeHost failed"); - } - result = false; - } - return result; - } - - protected virtual void OnClientDisconnectedFromHost(QSBNetworkConnection conn, out SceneChangeOption sceneChange) - { - sceneChange = SceneChangeOption.StayInOnlineScene; - } - - protected virtual void OnServerHostShutdown() - { - } - - protected virtual void OnServerReconnectPlayer(QSBNetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId) - { - this.ReconnectPlayerForConnection(newConnection, oldPlayer, oldConnectionId, playerControllerId); - } - - protected virtual void OnServerReconnectPlayer(QSBNetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId, NetworkReader extraMessageReader) - { - this.ReconnectPlayerForConnection(newConnection, oldPlayer, oldConnectionId, playerControllerId); - } - - protected virtual void OnServerReconnectObject(QSBNetworkConnection newConnection, GameObject oldObject, int oldConnectionId) - { - this.ReconnectObjectForConnection(newConnection, oldObject, oldConnectionId); - } - - protected virtual void OnPeersUpdated(QSBPeerListMessage peers) - { - Debug.Log("NetworkMigrationManager NumPeers " + peers.peers.Length); - } - - protected virtual void OnAuthorityUpdated(GameObject go, int connectionId, bool authorityState) - { - Debug.Log(string.Concat(new object[] - { - "NetworkMigrationManager OnAuthorityUpdated for ", - go, - " conn:", - connectionId, - " state:", - authorityState - })); - } - - public virtual bool FindNewHost(out QSBPeerInfoMessage newHostInfo, out bool youAreNewHost) - { - bool result; - if (this.m_Peers == null) - { - if (LogFilter.logError) - { - Debug.LogError("NetworkMigrationManager FindLowestHost no peers"); - } - newHostInfo = null; - youAreNewHost = false; - result = false; - } - else - { - Debug.Log("NetworkMigrationManager FindLowestHost"); - newHostInfo = new QSBPeerInfoMessage(); - newHostInfo.connectionId = 50000; - newHostInfo.address = ""; - newHostInfo.port = 0; - int num = -1; - youAreNewHost = false; - if (this.m_Peers == null) - { - result = false; - } - else - { - for (int i = 0; i < this.m_Peers.Length; i++) - { - QSBPeerInfoMessage peerInfoMessage = this.m_Peers[i]; - if (peerInfoMessage.connectionId != 0) - { - if (!peerInfoMessage.isHost) - { - if (peerInfoMessage.isYou) - { - num = peerInfoMessage.connectionId; - } - if (peerInfoMessage.connectionId < newHostInfo.connectionId) - { - newHostInfo = peerInfoMessage; - } - } - } - } - if (newHostInfo.connectionId == 50000) - { - result = false; - } - else - { - if (newHostInfo.connectionId == num) - { - youAreNewHost = true; - } - Debug.Log("FindNewHost new host is " + newHostInfo.address); - result = true; - } - } - } - return result; - } - - private void OnGUIHost() - { - int num = this.m_OffsetY; - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Was Shutdown ID(" + this.m_OldServerConnectionId + ")"); - num += 25; - if (Application.platform == RuntimePlatform.WebGLPlayer) - { - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Migration not supported for WebGL"); - } - else - { - if (this.m_WaitingReconnectToNewHost) - { - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Reconnect as Client")) - { - this.Reset(0); - if (NetworkManager.singleton != null) - { - NetworkManager.singleton.networkAddress = GUI.TextField(new Rect((float)(this.m_OffsetX + 100), (float)num, 95f, 20f), NetworkManager.singleton.networkAddress); - NetworkManager.singleton.StartClient(); - } - else - { - Debug.LogWarning("MigrationManager Old Host Reconnect - No NetworkManager."); - } - } - num += 25; - } - else - { - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Pick New Host")) - { - bool flag; - if (this.FindNewHost(out this.m_NewHostInfo, out flag)) - { - this.m_NewHostAddress = this.m_NewHostInfo.address; - if (flag) - { - Debug.LogWarning("MigrationManager FindNewHost - new host is self?"); - } - else - { - this.m_WaitingReconnectToNewHost = true; - } - } - } - num += 25; - } - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Leave Game")) - { - if (NetworkManager.singleton != null) - { - NetworkManager.singleton.SetupMigrationManager(null); - NetworkManager.singleton.StopHost(); - } - else - { - Debug.LogWarning("MigrationManager Old Host LeaveGame - No NetworkManager."); - } - this.Reset(-1); - } - num += 25; - } - } - - private void OnGUIClient() - { - int num = this.m_OffsetY; - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Lost Connection To Host ID(" + this.m_OldServerConnectionId + ")"); - num += 25; - if (Application.platform == RuntimePlatform.WebGLPlayer) - { - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "Host Migration not supported for WebGL"); - } - else - { - if (this.m_WaitingToBecomeNewHost) - { - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "You are the new host"); - num += 25; - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Start As Host")) - { - if (NetworkManager.singleton != null) - { - this.BecomeNewHost(NetworkManager.singleton.networkPort); - } - else - { - Debug.LogWarning("MigrationManager Client BecomeNewHost - No NetworkManager."); - } - } - num += 25; - } - else if (this.m_WaitingReconnectToNewHost) - { - GUI.Label(new Rect((float)this.m_OffsetX, (float)num, 200f, 40f), "New host is " + this.m_NewHostAddress); - num += 25; - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Reconnect To New Host")) - { - this.Reset(this.m_OldServerConnectionId); - if (NetworkManager.singleton != null) - { - NetworkManager.singleton.networkAddress = this.m_NewHostAddress; - NetworkManager.singleton.client.ReconnectToNewHost(this.m_NewHostAddress, NetworkManager.singleton.networkPort); - } - else - { - Debug.LogWarning("MigrationManager Client reconnect - No NetworkManager."); - } - } - num += 25; - } - else - { - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Pick New Host")) - { - bool flag; - if (this.FindNewHost(out this.m_NewHostInfo, out flag)) - { - this.m_NewHostAddress = this.m_NewHostInfo.address; - if (flag) - { - this.m_WaitingToBecomeNewHost = true; - } - else - { - this.m_WaitingReconnectToNewHost = true; - } - } - } - num += 25; - } - if (GUI.Button(new Rect((float)this.m_OffsetX, (float)num, 200f, 20f), "Leave Game")) - { - if (NetworkManager.singleton != null) - { - NetworkManager.singleton.SetupMigrationManager(null); - NetworkManager.singleton.StopHost(); - } - else - { - Debug.LogWarning("MigrationManager Client LeaveGame - No NetworkManager."); - } - this.Reset(-1); - } - num += 25; - } - } - - private void OnGUI() - { - if (this.m_ShowGUI) - { - if (this.m_HostWasShutdown) - { - this.OnGUIHost(); - } - else if (this.m_DisconnectedFromHost && this.m_OldServerConnectionId != -1) - { - this.OnGUIClient(); - } - } - } - - [SerializeField] - private bool m_HostMigration = true; - - [SerializeField] - private bool m_ShowGUI = true; - - [SerializeField] - private int m_OffsetX = 10; - - [SerializeField] - private int m_OffsetY = 300; - - private QSBNetworkClient m_Client; - - private bool m_WaitingToBecomeNewHost; - - private bool m_WaitingReconnectToNewHost; - - private bool m_DisconnectedFromHost; - - private bool m_HostWasShutdown; - - private MatchInfo m_MatchInfo; - - private int m_OldServerConnectionId = -1; - - private string m_NewHostAddress; - - private QSBPeerInfoMessage m_NewHostInfo = new QSBPeerInfoMessage(); - - private QSBPeerListMessage m_PeerListMessage = new QSBPeerListMessage(); - - private QSBPeerInfoMessage[] m_Peers; - - private Dictionary m_PendingPlayers = new Dictionary(); - - public enum SceneChangeOption - { - StayInOnlineScene, - SwitchToOfflineScene - } - - public struct PendingPlayerInfo - { - public NetworkInstanceId netId; - - public short playerControllerId; - - public GameObject obj; - } - - public struct ConnectionPendingPlayers - { - public List players; - } - } -} \ No newline at end of file diff --git a/QuantumUNET/QSBPeerAuthorityMessage.cs b/QuantumUNET/QSBPeerAuthorityMessage.cs deleted file mode 100644 index 1ef5ec75..00000000 --- a/QuantumUNET/QSBPeerAuthorityMessage.cs +++ /dev/null @@ -1,27 +0,0 @@ -using UnityEngine.Networking; - -namespace QuantumUNET -{ - public class QSBPeerAuthorityMessage : QSBMessageBase - { - public override void Deserialize(QSBNetworkReader reader) - { - this.connectionId = (int)reader.ReadPackedUInt32(); - this.netId = reader.ReadNetworkId(); - this.authorityState = reader.ReadBoolean(); - } - - public override void Serialize(QSBNetworkWriter writer) - { - writer.WritePackedUInt32((uint)this.connectionId); - writer.Write(this.netId); - writer.Write(this.authorityState); - } - - public int connectionId; - - public NetworkInstanceId netId; - - public bool authorityState; - } -} \ No newline at end of file diff --git a/QuantumUNET/QSBPeerListMessage.cs b/QuantumUNET/QSBPeerListMessage.cs deleted file mode 100644 index 17ab9241..00000000 --- a/QuantumUNET/QSBPeerListMessage.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace QuantumUNET -{ - public class QSBPeerListMessage : QSBMessageBase - { - public override void Deserialize(QSBNetworkReader reader) - { - this.oldServerConnectionId = (int)reader.ReadPackedUInt32(); - int num = (int)reader.ReadUInt16(); - this.peers = new QSBPeerInfoMessage[num]; - for (int i = 0; i < this.peers.Length; i++) - { - QSBPeerInfoMessage peerInfoMessage = new QSBPeerInfoMessage(); - peerInfoMessage.Deserialize(reader); - this.peers[i] = peerInfoMessage; - } - } - - public override void Serialize(QSBNetworkWriter writer) - { - writer.WritePackedUInt32((uint)this.oldServerConnectionId); - writer.Write((ushort)this.peers.Length); - for (int i = 0; i < this.peers.Length; i++) - { - this.peers[i].Serialize(writer); - } - } - - public QSBPeerInfoMessage[] peers; - - public int oldServerConnectionId; - } -} \ No newline at end of file diff --git a/QuantumUNET/QuantumUNET.csproj b/QuantumUNET/QuantumUNET.csproj index bd737170..019e0ae1 100644 --- a/QuantumUNET/QuantumUNET.csproj +++ b/QuantumUNET/QuantumUNET.csproj @@ -120,7 +120,6 @@ - @@ -133,10 +132,8 @@ - -