Example #1
0
    /// <summary>
    /// Callback for when a match was joined.
    /// </summary>
    private void OnMatchJoined(bool success, Match match)
    {
        if (success == false)
        {
            UIManager.Instance.ShowNotification("Could not connect to match");
            joinServerTrans.gameObject.SetActive(false);
            overviewTrans.gameObject.SetActive(true);
            return;
        }

        NetworkConnector.DisconnectClient();

        //NetworkManager.singleton.StartClient(match);
        NobleNetworkManager manager = (NobleNetworkManager)NetworkManager.singleton;
        string ip   = match.matchData["ipAddress"];
        int    port = match.matchData["port"];

        manager.networkAddress = ip;
        manager.networkPort    = (ushort)port;

        Config.Instance.LastConnectedGame = LastConnectedGame.Connected(ip, port);

        manager.StartClient();

        connectingScreen.Show();
        OnConfirm();
    }
Example #2
0
    public void JoinGame()
    {
        networkManager.InitClient();
        networkManager.networkAddress = ipfield.text;
        networkManager.networkPort    = ushort.Parse(portfield.text);

        networkManager.StartClient();
    }
Example #3
0
    public static IEnumerator TryConnectToServer(string networkAdress, ushort port, Action onSuccess = null, Action onFailure = null)
    {
        NobleNetworkManager networkManager = (NobleNetworkManager)NetworkManager.singleton;

        networkManager.StopHost();

        yield return(new WaitForSeconds(1.0f));

        try
        {
            networkManager.InitClient();

            networkManager.networkAddress = networkAdress;
            networkManager.networkPort    = port;

            networkManager.StartClient();
        }
        catch (Exception)
        {
            TryConnectToServerFailed(onFailure);
            yield break;
        }

        yield return(new WaitForSeconds(1.0f));

        float time = 0.0f;

        while (networkManager.isNetworkActive)
        {
            if (networkManager.client == null)
            {
                TryConnectToServerFailed(onFailure);
                yield break;
            }

            if (networkManager.client.isConnected)
            {
                onSuccess?.Invoke();
                yield break;
            }

            time += Time.deltaTime;
            if (time > 5.0f)
            {
                TryConnectToServerFailed(onFailure);
                yield break;
            }

            yield return(null);
        }
    }
Example #4
0
    // Draw the client GUI
    void GUIClient()
    {
        if (!networkManager.isNetworkActive)
        {
            // Text boxes for entering host's address
            GUI.Label(new Rect(10, 10, 150, 22), "Host IP:");
            hostIP = GUI.TextField(new Rect(170, 10, 420, 22), hostIP);
            GUI.Label(new Rect(10, 37, 150, 22), "Host Port:");
            hostPort = GUI.TextField(new Rect(170, 37, 160, 22), hostPort);

            // Connect button
            if (GUI.Button(new Rect(115, 81, 120, 30), "Connect"))
            {
                networkManager.networkAddress = hostIP;
                networkManager.networkPort    = ushort.Parse(hostPort);
                networkManager.StartClient();
            }

            // Back button
            if (GUI.Button(new Rect(10, 81, 95, 30), "Back"))
            {
                isClient = false;
            }
        }
        else if (networkManager.client != null)
        {
            // Disconnect button
            GUI.Label(new Rect(10, 10, 150, 22), "Connection type: " + networkManager.client.latestConnectionType);
            if (GUI.Button(new Rect(10, 50, 110, 30), "Disconnect"))
            {
                if (networkManager.client.isConnected)
                {
                    // If we are already connected it is best to quit gracefully by sending
                    // a disconnect message to the host.
                    networkManager.client.connection.Disconnect();
                    networkManager.client.connection.InvokeHandler(new DisconnectMessage(), -1);
                }
                else
                {
                    // If the connection is still in progress StopClient will cancel it
                    networkManager.StopClient();
                }
                isClient = false;
            }
        }
    }
Example #5
0
 public async Task JoinMatch(MvMatch match)
 {
     _joinMatchTask = new TaskCompletionSource();
     JoinMatch(new Match(Convert.ToInt64(match.Id)), (success, match) =>
     {
         if (success)
         {
             _networkManager.networkAddress = match.matchData["HostAddress"];
             _networkManager.networkPort    = match.matchData["HostPort"];
             _networkManager.StartClient();
         }
         else
         {
             _joinMatchTask.SetException(new MvException());
         }
     });
     await _joinMatchTask.Task;
 }
Example #6
0
    private void OnReconnectButtonPressed()
    {
        LastConnectedGame lcg = Config.Instance.LastConnectedGame;

        if (lcg == null)
        {
            return;
        }

        NetworkConnector.DisconnectClient();

        NobleNetworkManager manager = (NobleNetworkManager)NetworkManager.singleton;

        manager.networkAddress = lcg.lastConnectedIP;
        manager.networkPort    = (ushort)lcg.lastConnectedPort;

        manager.StartClient();

        connectingScreen.Show();
        OnConfirm();
    }