예제 #1
0
        protected void ValidateCredentials(Connection.Tcp connection)
        {
            Message.Connection.Request request = new Message.Connection.Request
            {
                version  = connection.version,
                username = credentials.username,
                password = credentials.password
            };

            connection.Send(request);

            Message.Base v;

            if (connection.Receive(out v) && v.IsType <Message.Connection.Validation>())
            {
                Message.Connection.Validation validation = (Message.Connection.Validation)v;

                // Check if the sent credentials are OK
                if (validation.accepted)
                {
                    NegotiateChannels(connection);
                }
                else
                {
                    Drop(connection, "Invalid credentials.");
                }
            }
            else
            {
                Drop(connection, "Expected to receive credentials validation.");
            }
        }
예제 #2
0
        protected void ValidateCredentials(Connection.Tcp connection)
        {
            Message.Base req;

            if (connection.Receive(out req) && req.IsType <Message.Connection.Request>())
            {
                Message.Connection.Request request = (Message.Connection.Request)req;

                connection.version = request.version;

                if (connection.version < maxSupportedVersion)
                {
                    Debug.LogWarningFormat("Client does not support protocol version '{0}'. Using version '{1}' instead.", maxSupportedVersion, connection.version);
                }

                Message.Connection.Validation validation = new Message.Connection.Validation();

                // Check if the credentials are valid
                if (request.username == credentials.username && request.password == credentials.password)
                {
                    validation.accepted = true;

                    // Notify the client that the credentials are valid
                    connection.Send(validation);

                    NegotiateChannels(connection);
                }
                else
                {
                    string error_message = string.Format("Invalid connection credentials for user '{0}'. Dropping connection.", request.username);

                    Debug.LogWarning(error_message);

                    validation.accepted = false;

                    // Notify the client that the credentials are wrong
                    connection.Send(validation);

                    // Drop the connection
                    Close(connection);

                    throw new DropException(error_message);
                }
            }
            else
            {
                Drop(connection, "Expected to receive negotiation connection request.");
            }
        }