/// <summary>
    /// Creates a new FacepunchP2PClient and attempts to connect to the specified SteamId
    /// </summary>
    /// <param name="hostSteamId">SteamId of the host/server</param>
    private void ConnectToServer(SteamId hostSteamId)
    {
        var client = new FacepunchP2PClient();

        client.Connect(hostSteamId);
        Connected(client);
    }
Пример #2
0
        /// <summary>
        /// Handle the connecting the selected lobby/server
        /// </summary>
        public void Connect()
        {
            SetToggledButtons(false);
            IsConnecting = true;

            if (connectUsingMatchmaking)
            {
                // Add custom matchmaking logic here.
                // eg.: pick a random lobby from the list of lobbies for the game
                return;
            }

            // Need to select a lobby first.
            if (selectedLobby.Id == 0)
            {
                return;
            }

            NetWorker client;

            client = new FacepunchP2PClient();
            ((FacepunchP2PClient)client).Connect(selectedLobby);
            FacepunchSteamworksController.SetNetworker((BaseFacepunchP2P)client);

            // Steamworks API calls are async so we need to delay the rest of the networker setup until
            // the local user joins the selected lobby.
            client.bindSuccessful += (networker) => {
                MainThreadManager.Run(() =>
                {
                    Connected(client);
                });
            };

            client.bindFailure += (sender) =>
            {
                MainThreadManager.Run(() =>
                {
                    ResetButtonsOnFailedConnection();
                });
            };

            client.disconnected += (sender) =>
            {
                MainThreadManager.Run(() =>
                {
                    ResetButtonsOnFailedConnection();
                });
            };
        }
Пример #3
0
    public void ConnectToHost(SteamId hostSteamId, UnityEngine.UI.Text connectionText)
    {
        string info = "Starting Client connection to lobby owner (host): " + hostSteamId.Value.ToString();

        BMSLog.Log(info);
        if (connectionText != null)
        {
            connectionText.text = info;
        }

        networkManager = GetNetworkManager();
        steamP2PClient = new FacepunchP2PClient();
        networkManager.Initialize(steamP2PClient);
        ((FacepunchP2PClient)steamP2PClient).bindSuccessful += OnClientBindSuccessful;
        ((FacepunchP2PClient)steamP2PClient).serverAccepted += OnClientServerAccepted;
        ((FacepunchP2PClient)steamP2PClient).disconnected   += OnClientDisconnected;
        ((FacepunchP2PClient)steamP2PClient).Connect(hostSteamId);

        // Moved initialize after Connect() call and callbacks and this along with the 1 cycle delay on setting up the ReadNetwork thread seems to stop the
        // SteamNetworking NRE problems.
        //networkManager.Initialize(steamP2PClient);
        Connected(steamP2PClient);
    }