public void IsolateClient(LobbyCloser closer) { if (!iAmServer) { Debug.Log("Isolating client..."); Unregister(myPlayerId, closer); } }
public void IsolateHost(LobbyCloser closer) { if (iAmServer) { Debug.Log("Isolating host..."); bool isFirst = true; int port = netManager.networkPort + 1; string address = ""; RemoveOwnership(); foreach (var player in currentPlayerGroup) { if (player != myPlayerId) { if (isFirst) { Debug.Log("Setting up split's host"); RpcBecomeHost(player, currentPlayerGroup.Count, port, false, ""); isFirst = false; address = playersIpAddresses[player]; } else { Debug.Log("Reconnecting splitted clients to the new host."); RpcChangeClientConnection(player, port, address); } } } foreach (var player in nextPlayerGroup) { if (player != myPlayerId) { if (isFirst) { Debug.Log("Setting up split's host"); RpcBecomeHost(player, currentPlayerGroup.Count, port, false, ""); isFirst = false; address = playersIpAddresses[player]; } else { Debug.Log("Reconnecting splitted clients to the new host."); RpcChangeClientConnection(player, port, address); } } } GameObject.FindWithTag("PlayersFinder").GetComponent <NetworkDiscovery>().StopBroadcast(); CloseHost(closer); } }
IEnumerator WaitBeforeClosing(LobbyCloser closer) { while (netManager.numPlayers > 1) { Debug.Log("Waiting, currently connected players: " + netManager.numPlayers); yield return(new WaitForSeconds(0.01f)); } DestroyChat(); netManager.StopHost(); Destroy(gameObject); if (closer != null) { closer.Close(); } }
IEnumerator WaitAuthorityUnregister(uint id, LobbyCloser closer) { GetAuthority(); if (!iAmServer) { NetworkIdentity netIdentity = GetComponent <NetworkIdentity>(); while (!netIdentity.hasAuthority) { yield return(new WaitForSeconds(0.01f)); } } CmdUnregister(id); Debug.Log("Client has been unregistered."); StartCoroutine(WaitToAuthorityRemoval(closer)); }
IEnumerator WaitToAuthorityRemoval(LobbyCloser closer) { if (!iAmServer) { NetworkIdentity netIdentity = GetComponent <NetworkIdentity>(); while (netIdentity.hasAuthority) { yield return(new WaitForSeconds(0.01f)); } NetworkServer.Destroy(GameObject.FindWithTag("LocalPlayer")); DestroyChat(); netManager.StopClient(); Debug.Log("Closing game..."); Destroy(gameObject); closer.Close(); } }
private Coroutine CloseHost(LobbyCloser closer = null) => StartCoroutine(WaitBeforeClosing(closer));
private Coroutine Unregister(uint id, LobbyCloser closer) => StartCoroutine(WaitAuthorityUnregister(id, closer));