Exemplo n.º 1
0
 public void IsolateClient(LobbyCloser closer)
 {
     if (!iAmServer)
     {
         Debug.Log("Isolating client...");
         Unregister(myPlayerId, closer);
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 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();
     }
 }
Exemplo n.º 6
0
 private Coroutine CloseHost(LobbyCloser closer = null) => StartCoroutine(WaitBeforeClosing(closer));
Exemplo n.º 7
0
 private Coroutine Unregister(uint id, LobbyCloser closer) => StartCoroutine(WaitAuthorityUnregister(id, closer));