Example #1
0
        private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            string password = Encoding.ASCII.GetString(connectionData);

            bool approveConnection = password == passwordInputField.text;

            Vector3    spawnPos = Vector3.zero;
            Quaternion spawnRot = Quaternion.identity;

            switch (NetworkManager.Singleton.ConnectedClients.Count)
            {
            case 0:
                spawnPos = new Vector3(-2f, 0f, 0f);
                spawnRot = Quaternion.Euler(0f, 135f, 0f);
                break;

            case 1:
                spawnPos = new Vector3(0f, 0f, 0f);
                spawnRot = Quaternion.Euler(0f, 180f, 0f);
                break;

            case 2:
                spawnPos = new Vector3(2f, 0f, 0f);
                spawnRot = Quaternion.Euler(0f, 225, 0f);
                break;
            }

            callback(true, null, approveConnection, spawnPos, spawnRot);
        }
Example #2
0
        private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            string payload           = Encoding.ASCII.GetString(connectionData);
            var    connectionPayload = JsonUtility.FromJson <ConnectionPayload>(payload);

            bool approveConnection = connectionPayload.password == passwordInputField.text;

            Vector3    spawnPos = Vector3.zero;
            Quaternion spawnRot = Quaternion.identity;

            if (approveConnection)
            {
                switch (NetworkManager.Singleton.ConnectedClients.Count)
                {
                case 1:
                    spawnPos = new Vector3(0f, 0f, 0f);
                    spawnRot = Quaternion.Euler(0f, 180f, 0f);
                    break;

                case 2:
                    spawnPos = new Vector3(2f, 0f, 0f);
                    spawnRot = Quaternion.Euler(0f, 225, 0f);
                    break;
                }

                clientData[clientId] = new PlayerData(connectionPayload.playerName);
            }

            callback(true, null, approveConnection, spawnPos, spawnRot);
        }
Example #3
0
    //--------------------------------------------------------------------------------------
    // ApprovalCheck: Event running approval check for server connection
    //
    // Param:
    //      baConnectionData: An Array of bytes representing the connection data for server setup
    //      ulClientID: A ulong for Client ID
    //      Callback: A NetworkingManager.ConnectionApprovedDelegate for setting callback delegate.
    //--------------------------------------------------------------------------------------
    private void ApprovalCheck(byte[] baConnectionData, ulong ulClientID, NetworkManager.ConnectionApprovedDelegate Callback)
    {
        // New string for internal server password
        string strPassword = Encoding.ASCII.GetString(baConnectionData);

        // Check if the password matches
        bool bApproveConnection = strPassword == m_ifPassword.text;

        ////////////////// TEMP: MOVE TO MATCH MANAGER LATER AND SPAWN RANDOMLY //////////////////

        // new variables for spawn position of players
        Vector2    v2SpawnPos = Vector2.zero;
        Quaternion qSpawnRot  = Quaternion.identity;

        // Switch through each connected client (Other than host)
        switch (NetworkManager.Singleton.ConnectedClients.Count)
        {
        // Set spawn pos of next connected player
        case 1:
            v2SpawnPos = new Vector2(0f, 0f);
            qSpawnRot  = Quaternion.Euler(0f, 0f, 0f);
            break;

        // Set spawn pos of next connected player
        case 2:
            v2SpawnPos = new Vector2(0f, 5f);
            qSpawnRot  = Quaternion.Euler(0f, 0f, 0f);
            break;
        }

        ////////////////// TEMP: MOVE TO MATCH MANAGER LATER AND SPAWN RANDOMLY //////////////////

        // Run approval callback
        Callback(true, null, bApproveConnection, v2SpawnPos, qSpawnRot);
    }
Example #4
0
    private void ApprovalCheck(byte[] connectionData, ulong clientID, NetworkManager.ConnectionApprovedDelegate callback)
    {
        //check data
        bool approve = System.Text.Encoding.ASCII.GetString(connectionData) == "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";

        callback(true, null, approve, Vector3.zero, Quaternion.identity);
    }
Example #5
0
        private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            if (connectionData.Length > MaxConnectionPayload)
            {
                callback(false, 0, false, null, null);
                return;
            }

            if (clientId == NetworkManager.Singleton.LocalClientId)
            {
                callback(false, null, true, null, null);
                return;
            }

            string payload           = Encoding.UTF8.GetString(connectionData);
            var    connectionPayload = JsonUtility.FromJson <ConnectionPayload>(payload);

            ConnectStatus gameReturnStatus = ConnectStatus.Success;

            // This stops us from running multiple standalone builds since
            // they disconnect eachother when trying to join
            //
            // if (clientData.ContainsKey(connectionPayload.clientGUID))
            // {
            //     ulong oldClientId = clientData[connectionPayload.clientGUID].ClientId;
            //     StartCoroutine(WaitToDisconnectClient(oldClientId, ConnectStatus.LoggedInAgain));
            // }

            if (gameInProgress)
            {
                gameReturnStatus = ConnectStatus.GameInProgress;
            }
            else if (clientData.Count >= maxPlayers)
            {
                gameReturnStatus = ConnectStatus.ServerFull;
            }

            if (gameReturnStatus == ConnectStatus.Success)
            {
                clientSceneMap[clientId] = connectionPayload.clientScene;
                clientIdToGuid[clientId] = connectionPayload.clientGUID;
                clientData[connectionPayload.clientGUID] = new PlayerData(connectionPayload.playerName, clientId);
            }

            callback(false, 0, true, null, null);

            gameNetPortal.ServerToClientConnectResult(clientId, gameReturnStatus);

            if (gameReturnStatus != ConnectStatus.Success)
            {
                StartCoroutine(WaitToDisconnectClient(clientId, gameReturnStatus));
            }
        }
Example #6
0
    private void ApprovalCheck(byte[] connectionData, ulong clientID, NetworkManager.ConnectionApprovedDelegate callback)
    {
        bool approve = false;
        //if connection is correct then approve
        string password = System.Text.Encoding.ASCII.GetString(connectionData);

        if (password == "mygame")
        {
            approve = true;
        }

        //If approve is true, the connection gets added. If it's false. The client gets disconnected
        callback(true, null, approve, new Vector3(0, 10, 0), Quaternion.identity);
    }
Example #7
0
        private void ConnectionApprovalCallback(byte[] arg1, ulong arg2, NetworkManager.ConnectionApprovedDelegate arg3)
        {
            string approvalToken = Encoding.ASCII.GetString(arg1);
            var    isTokenValid  = approvalToken == m_ApprovalToken;

            if (m_SimulateFailure && m_SimulateFailure.isOn && IsServer && arg2 != NetworkManager.LocalClientId)
            {
                isTokenValid = false;
            }

            if (isTokenValid)
            {
                if (m_GlobalObjectIdHashOverride != 0 && m_PlayerPrefabOverride && m_PlayerPrefabOverride.isOn)
                {
                    arg3.Invoke(true, m_GlobalObjectIdHashOverride, true, null, null);
                }
                else
                {
                    arg3.Invoke(true, null, true, null, null);
                }
            }
            else
            {
                NetworkManager.DisconnectClient(arg2);
                Debug.LogWarning($"User id {arg2} was disconnected due to failed connection approval!");
            }

            if (m_ConnectionMessageToDisplay && arg2 != NetworkManager.LocalClientId)
            {
                if (isTokenValid)
                {
                    m_ConnectionMessageToDisplay.text = $"Client id {arg2} is authorized!";
                }
                else
                {
                    m_ConnectionMessageToDisplay.text = $"Client id {arg2} failed authorization!";
                }

                m_ConnectionMessageToDisplay.gameObject.SetActive(true);
                StartCoroutine(WaitToHideConnectionText());
            }
        }
Example #8
0
        /// <summary>
        /// Gets executed on the server when a client wants to connect with the given connection data.
        /// </summary>
        private void HandleApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            // Get connection data of connected client (not if we as the host just joined ourselves)
            NetworkConnectionData data = null;

            if (clientId != NetworkManager.Singleton.LocalClientId)
            {
                data          = (NetworkConnectionData)Deserialize(connectionData);
                data.ClientId = clientId;
            }

            bool approveConnection = true;

            callback(true, null, approveConnection, null, null);

            if (approveConnection && clientId != NetworkManager.Singleton.LocalClientId)
            {
                Debug.Log("NETWORK: Incoming client connection, Approval: " + approveConnection + "\n" + data.ToString());
                ConnectionData.Add(clientId, data);
            }
        }
Example #9
0
 private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
 {
     callback(true, null, true, null, null);
 }
Example #10
0
        private static void ClientConnectionApproval(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            ulong?prefabHash = NetworkSpawnManager.GetPrefabHashFromGenerator(PlayerPrefabHashString);

            callback(true, prefabHash, true, SpawnLocationManager.GetRandomSpawn(), Quaternion.identity);
        }
Example #11
0
        private void OnConnectionApprovalCallback(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            var character = (Character)connectionData[0];

            if (_SessionManager.Count() == PlayerCount)
            {
                CBSL.Logging.Logger.Warn <NetworkController>("Max player count reached");
                callback(false, null, false, null, null);
            }

            _SessionManager.AddPlayer(clientId, character);
            callback(false, null, true, null, null);
        }
        private void NetworkManagerObject_ConnectionApprovalCallback(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
        {
            var stringGuid = Encoding.UTF8.GetString(connectionData);

            if (m_ValidationToken.ToString() == stringGuid)
            {
                m_IsValidated = true;
            }
            callback(false, null, m_IsValidated, null, null);
        }