/// <summary> /// Is host active ? /// </summary> public static bool IsHost() { if (!NetworkStatus.IsServer()) { return(false); } return(NetworkServer.localClientActive); }
void Update() { if (NetworkStatus.IsServerStarted()) { UpdateBroadcastData(); // assign broadcast data // m_customNetworkDiscovery.broadcastData = ConvertDictionaryToString (m_dataForBroadcasting); } }
public static void MarkPlayerForSpawning(Player p) { if (!NetworkStatus.IsServerStarted()) { return; } if (!m_playersMarkedForSpawning.Contains(p)) { m_playersMarkedForSpawning.Add(p); } }
public override void OnStartClient() { base.OnStartClient(); if (!NetworkStatus.IsServer()) { if (this.playerOwnerGameObject) { this.playerOwner = this.playerOwnerGameObject.GetComponent <Player> (); } else { this.playerOwner = null; } } }
void Start() { Menu.Console.onDrawStats += () => { if (NetworkStatus.IsServerStarted()) { GUILayout.Label(GetTextForConsole()); } }; Menu.Console.RegisterStats(() => { if (NetworkStatus.IsServerStarted()) { return(GetTextForConsole()); } return(""); }); }
void OnSceneChanged(SceneChangedInfo info) { if (!NetworkStatus.IsServer()) { return; } if (this.resetTeamOnSceneChange) { m_team = ""; m_isSpectator = true; m_shouldChooseTeam = false; m_shouldSendChooseTeamMessage = false; this.OfferPlayerToChooseTeam(); } }
// Update is called once per frame void Update() { if (!NetworkStatus.IsServerStarted()) { return; } // spawn all players which are marked for spawning m_playersMarkedForSpawning.RemoveAll(delegate(Player p) { if (null == p) { return(true); } if (!p.IsLoggedIn()) { return(true); } if (null == p.GetControllingGameObject()) { Vector3 pos = new Vector3(); Quaternion rot = Quaternion.identity; if (CanPlayerBeSpawnedAtAnySpawnPosition(p, ref pos, ref rot)) { if (p.CreateGameObjectForPlayer(pos, rot) != null) { Debug.Log("Spawned game object for " + p.playerName); } else { Debug.LogError("Failed to create game object for " + p.playerName); } return(true); } else { // failed to find spawn location for player's game object // try next time } } return(false); }); }
void Update() { if (this.changeButtonTextWhileConnecting) { if (m_text) { string newText = ""; if (NetworkStatus.IsClientConnecting()) { // if client is connecting, change text m_stringBuilder.Length = 0; m_stringBuilder.Append(this.prefixText); int numDots = ((int)Time.realtimeSinceStartup) % 4; for (int i = 0; i < numDots; i++) { m_stringBuilder.Append("."); } newText = m_stringBuilder.ToString(); } else { // restore original text newText = m_originalButtonText; } if (newText != m_text.text) { m_text.text = newText; } } } if (this.disableButtonWhileClientIsActive) { // if client is active, disable button if (m_button) { m_button.interactable = !NetworkStatus.IsClientActive(); } } }
void Update() { // calculate average fps float timeElapsed = this.fpsStopwatch.ElapsedMilliseconds / 1000f; if (0f == timeElapsed) { timeElapsed = float.PositiveInfinity; } this.fpsStopwatch.Reset(); this.fpsStopwatch.Start(); float fpsNow = 1.0f / timeElapsed; fpsSum += fpsNow; fpsSumCount++; if (Time.time - lastTimeFpsUpdated > secondsToUpdateFps) { // Update average fps if (fpsSumCount > 0) { averageFps = fpsSum / fpsSumCount; } else { averageFps = 0; } fpsSum = 0; fpsSumCount = 0; lastTimeFpsUpdated = Time.time; } if (NetworkStatus.IsClientConnecting()) { this.timePassedSinceStartedConnectingToServer += Time.deltaTime; } }
private static System.Collections.IEnumerator BroadcastCoroutine() { while (true) { yield return(new WaitForSecondsRealtime(1.5f)); if (!m_isBroadcasting) { continue; } if (!NetworkStatus.IsServerStarted()) { continue; } if (null == m_serverUdpCl) { continue; } // TODO: data should be broadcasted to internal networks only ? e.g. those that start with 192 // TODO: should we send to every local IP, or just to broadcast IP (255.255.255.255) // measured time: average 0.8 ms for 2 IP addresses // var stopwatch = System.Diagnostics.Stopwatch.StartNew (); Profiler.BeginSample("Broadcast"); Utilities.Utilities.RunExceptionSafe(() => { Profiler.BeginSample("GetLocalIPv4Addresses"); var localAddresses = GetLocalIPv4Addresses(); Profiler.EndSample(); // Debug.Log("local addresses: \n" + string.Join("\n", localAddresses.Select( ip => ip.ToString() ).ToArray() ) ); Profiler.BeginSample("ConvertDictionaryToByteArray"); byte[] buffer = ConvertDictionaryToByteArray(m_dataForBroadcasting); Profiler.EndSample(); IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, m_clientPort); foreach (var address in localAddresses) { // convert it to broadcast address byte[] addressBytes = address.GetAddressBytes(); addressBytes[3] = 255; endPoint.Address = new IPAddress(addressBytes); Profiler.BeginSample("UdpClient.Send"); try { m_serverUdpCl.Send(buffer, buffer.Length, endPoint); } catch (SocketException ex) { if (ex.ErrorCode == 10051) { // Network is unreachable // ignore this error } else { throw; } } Profiler.EndSample(); } }); Profiler.EndSample(); // Debug.Log ("Broadcast send time: " + stopwatch.GetElapsedMicroSeconds() + " us"); } }
/// <summary> /// Is server active ? /// </summary> public static bool IsServer() { return(NetworkStatus.IsServerStarted()); }
public static bool IsClientActive() { return(!NetworkStatus.IsClientDisconnected()); }
/// <summary> /// Is client connected ? /// TODO: This method should be corrected to return: is client active. /// </summary> public static bool IsClient() { return(NetworkStatus.IsClientConnected()); }
// Update is called once per frame void Update() { if (!NetworkStatus.IsServerStarted() && !NetworkStatus.IsClientConnected()) { m_currentlySpectatedObject = null; return; } if (NetworkStatus.IsClient()) { if (Player.local != null) { if (Player.local.GetControllingGameObject() != null) { // controlling object is alive // set watched object to null m_currentlySpectatedObject = null; } else { // controlling object is not alive if (null == m_currentlySpectatedObject || null == m_currentlySpectatedObject.GetControllingGameObject()) { // we are not spectating anyone // find object for spectating FindObjectForSpectating(0); } else { // we are spectating someone } } } else { // we are on client, and there is no local player m_currentlySpectatedObject = null; } } else if (NetworkStatus.IsServer()) { // we are on dedicated server if (null == m_currentlySpectatedObject || null == m_currentlySpectatedObject.GetControllingGameObject()) { // we are not spectating anyone // find object for spectating FindObjectForSpectating(0); } } // just in case if (m_currentlySpectatedObject) { if (!m_currentlySpectatedObject.GetControllingGameObject()) { // controlling game object of spectated player is dead m_currentlySpectatedObject = null; } } }
public static bool IsClient(this NetworkManager netMgr) { return(NetworkStatus.IsClientConnected()); }
public static bool IsServer(this NetworkManager netMgr) { return(NetworkStatus.IsServerStarted()); }