void EntityImporterBase::operation(const Operation & op)
{
    //std::cout << "Got op ==================" << std::endl;
    //debug_dump(op, std::cout);

    if (m_state == CANCEL) {
        m_state = CANCELLED;
        return;
    }
    if (m_state == CANCELLED) {
        return;
    }
    OpVector res;
    if (op->getClassNo() == Atlas::Objects::Operation::INFO_NO) {
        infoArrived(op, res);
    } else if (op->getClassNo() == Atlas::Objects::Operation::ERROR_NO) {
        errorArrived(op, res);
    } else if (op->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
        sightArrived(op, res);
    }

    for (auto& resOp : res) {
        sendOperation(resOp);
    }

}
Example #2
0
HandlerResult TerrainModProperty::operation(LocatedEntity * ent,
                                            const Operation & op,
                                            OpVector & res)
{
    if (op->getClassNo() == Atlas::Objects::Operation::DELETE_NO) {
        return delete_handler(ent, op, res);
    } else if (op->getClassNo() == Atlas::Objects::Operation::MOVE_NO) {
        return move_handler(ent, op, res);
    }
    return OPERATION_IGNORED;
}
Example #3
0
void TrustedConnectionCreatorintegration::test_external_op_puppet()
{
    // Dispatching a Talk external op from the creator, to the creator should
    // result in it being passed directly to the normal op dispatch,
    // shortcutting the world.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Entity * other = new Entity(compose("%1", m_id_counter), m_id_counter++);
    other->setType(m_creatorType);
    m_server->m_world.addEntity(other);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(other->getId());

    m_connection->externalOperation(op, *m_connection);

    // Operation should be via world dispatch, as if it was from the Entity
    // we are puppeting.
    ASSERT_TRUE(m_BaseWorld_message_called.isValid());
    ASSERT_EQUAL(m_BaseWorld_message_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_BaseWorld_message_called->isDefaultTo());
    ASSERT_EQUAL(m_BaseWorld_message_called->getTo(), other->getId());
    ASSERT_NOT_NULL(m_BaseWorld_message_called_from);
    ASSERT_EQUAL(m_BaseWorld_message_called_from, other);
}
Example #4
0
void Juncture::OtherOperation(const Operation & op, OpVector & res)
{
    const int op_type = op->getClassNo();
    if (op_type == Atlas::Objects::Operation::CONNECT_NO) {
        return customConnectOperation(op, res);
    }
}
Example #5
0
void Admin::OtherOperation(const Operation & op, OpVector & res)
{
    const int op_type = op->getClassNo();
    if (op_type == Atlas::Objects::Operation::MONITOR_NO) {
        return customMonitorOperation(op, res);
    }
}
Example #6
0
void Entity::operation(const Operation & op, OpVector & res)
{
    if (m_script != 0 &&
        m_script->operation(op->getParents().front(), op, res) != 0) {
        return;
    }

    auto J = m_delegates.equal_range(op->getClassNo());
    HandlerResult hr = OPERATION_IGNORED;
    for (;J.first != J.second; ++J.first) {
        HandlerResult hr_call = callDelegate(J.first->second, op, res);
        //We'll record the most blocking of the different results only.
        if (hr != OPERATION_BLOCKED) {
            if (hr_call != OPERATION_IGNORED) {
                hr = hr_call;
            }
        }
        // How to access the property? We need a non-const pointer to call
        // operation, but to get this easily we need to force instantiation
        // from the type dict, making properties way less efficient.
        // Making the operation() method const strongly limits the usefulness
        // of delegates, but if we fetch the pointer the hard way, we then
        // require the method to handle instantiation on demand.
        //
        // Can we make a clean way to handle the property in the general case
        // handle instantiation itself? Making it responsible for copying
        // itself on instantiation would be faster than the
        // get/set/PropertyManager currently required in in modProperty.
    }
    //If the operation was blocked we shouldn't send it on to the entity.
    if (hr == OPERATION_BLOCKED) {
        return;
    }
    return callOperation(op, res);
}
Example #7
0
void EntityImporterBase::operation(const Operation & op)
{
    if (m_state == CANCEL) {
        m_state = CANCELLED;
        return;
    }
    if (m_state == CANCELLED) {
        return;
    }
    OpVector res;
    if (op->getClassNo() == Atlas::Objects::Operation::INFO_NO) {
        infoArrived(op, res);
    } else if (op->getClassNo() == Atlas::Objects::Operation::ERROR_NO) {
        errorArrived(op, res);
    } else if (op->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
        sightArrived(op, res);
    }

    for (auto& op : res) {
        sendOperation(op);
    }

}
Example #8
0
void Juncture::operation(const Operation & op, OpVector & res)
{
    const OpNo op_no = op->getClassNo();
    switch (op_no) {
        case Atlas::Objects::Operation::LOGIN_NO:
            LoginOperation(op, res);
            break;
        case OP_INVALID:
            break;
        default:
            OtherOperation(op, res);
            break;
    }
}
Example #9
0
void WaitForDeletionTask::operation(const Operation & op, OpVector & res)
{
    if (op->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
        if (!op->getArgs().empty()) {
            auto& innerOp = op->getArgs().front();
            if (innerOp->getClassNo() == Atlas::Objects::Operation::DELETE_NO) {
                auto deleteOp = Atlas::Objects::smart_dynamic_cast<Operation>(innerOp);
                if (!deleteOp->getArgs().empty()) {
                    auto args = deleteOp->getArgs().front();
                    if (args->getId() == m_entityId) {
                        m_complete = true;
                    }
                }
            }
        }
    }
}
Example #10
0
void RuleTraversalTask::operation(const Operation & op, OpVector & res)
{
    if (!op->isDefaultRefno() && op->getRefno() == mSerial) {
        if (op->getClassNo() == Atlas::Objects::Operation::INFO_NO) {
            if (!op->getArgs().empty()) {
                const auto& arg = op->getArgs().front();
                if (arg.isValid()) {
                    bool result = mVisitor(arg);
                    if (result) {
                        Element childrenElement;
                        if (arg->copyAttr("children", childrenElement) == 0 && childrenElement.isList() && !childrenElement.List().empty()) {
                            const ListType& childrenList = childrenElement.asList();
                            mStack.emplace_back();
                            for (auto& childElement : childrenList) {
                                if (childElement.isString()) {
                                    mStack.back().children.push_back(childElement.String());
                                }
                            }
                            mStack.back().currentChildIterator = mStack.back().children.begin();
                            getRule(*mStack.back().currentChildIterator, res);
                            return;
                        } else {
                            while (!mStack.empty()) {
                                StackEntry& stackEntry = mStack.back();
                                stackEntry.currentChildIterator++;
                                if (stackEntry.currentChildIterator == stackEntry.children.end()) {
                                    mStack.pop_back();
                                } else {
                                    getRule(*stackEntry.currentChildIterator, res);
                                    return;
                                }
                            }
                            m_complete = true;
                        }
                    } else {
                        m_complete = true;
                    }
                }
            }
        }
    }
}
Example #11
0
/// \brief Execute an operation sent by a connected peer
///
/// \param op The operation to be executed
/// \param res The result set of replies
void Peer::operation(const Operation &op, OpVector &res)
{
    if (!op->isDefaultRefno()) {
        replied.emit(op);
    }

    const OpNo op_no = op->getClassNo();
    switch (op_no) {
        case Atlas::Objects::Operation::INFO_NO:
        {
            // If we receive an Info op while we are not yet authenticated, it
            // can only be the result of an authentication request.
            if (m_state == PEER_AUTHENTICATING) {
                const std::vector<Root> & args = op->getArgs();
                if (args.empty()) {
                    return;
                }
                const Root & arg = args.front();
                if (!arg->hasAttrFlag(Atlas::Objects::ID_FLAG)) {
                    return;
                }
                // Response to a Login op
                m_accountId = arg->getId();
                if (!arg->getParents().empty()) {
                    m_accountType = arg->getParents().front();
                }
                m_state = PEER_AUTHENTICATED;
            } else if (m_state == PEER_AUTHENTICATED) {
                // If we received an Info op while authenticated, it is a
                // response to a teleport request.
                peerTeleportResponse(op, res);
            }
        }
        break;
        case Atlas::Objects::Operation::ERROR_NO:
        {
            m_state = PEER_FAILED;
        }
        break;
    }
}
Example #12
0
void ConnectionCharacterintegration::test_external_op()
{
    // Dispatching a Talk external op from the character should result in
    // it being passed on to the world.

    m_character->linkExternal(m_connection);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_character->getId());

    m_connection->externalOperation(op, *m_connection);

    // BaseWorld::message should have been called from Enitty::sendWorld
    // with the Talk operation, modified to have TO set to the character.
    ASSERT_TRUE(m_BaseWorld_message_called.isValid());
    ASSERT_EQUAL(m_BaseWorld_message_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_BaseWorld_message_called->isDefaultTo());
    ASSERT_EQUAL(m_BaseWorld_message_called->getTo(), m_character->getId());
    ASSERT_NOT_NULL(m_BaseWorld_message_called_from);
    ASSERT_EQUAL(m_BaseWorld_message_called_from, m_character);
}
Example #13
0
void ConnectionCharacterintegration::test_connect_up()
{
    // Dispatching an external op from the character should cause it to
    // get connected up with an external mind

    RootOperation op;
    op->setFrom(m_character->getId());

    ASSERT_NULL(m_character->m_externalMind);

    m_connection->externalOperation(op, *m_connection);

    ASSERT_NOT_NULL(m_character->m_externalMind);
    ExternalMind * em =
          dynamic_cast<ExternalMind*>(m_character->m_externalMind);
    ASSERT_NOT_NULL(em);
    ASSERT_TRUE(em->isLinked());
    ASSERT_TRUE(em->isLinkedTo(m_connection));
    ASSERT_TRUE(m_Link_send_sent.isValid());
    ASSERT_EQUAL(m_Link_send_sent->getClassNo(),
                 Atlas::Objects::Operation::INFO_NO);
    ASSERT_EQUAL(m_logEvent_logged, TAKE_CHAR);
}
Example #14
0
void TrustedConnectionCreatorintegration::test_external_op_override()
{
    // Dispatching a Talk external op from the creator should result in
    // it being passed on to the world, exactly as if this was a Character
    // except that we assume that Creator was set up linked.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(m_creator->getId());

    m_connection->externalOperation(op, *m_connection);

    // The operation should have been passed to Entity::callOperation for
    // dispatch, completely unfiltered.
    ASSERT_TRUE(m_Entity_callOperation_called.isValid());
    ASSERT_EQUAL(m_Entity_callOperation_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_Entity_callOperation_called->isDefaultTo());
    ASSERT_EQUAL(m_Entity_callOperation_called->getTo(), m_creator->getId());
}
Example #15
0
void TrustedConnectionCreatorintegration::test_external_op()
{
    // Dispatching a Talk external op from the creator should result in
    // it being passed on to the world, exactly as if this was a Character
    // except that we assume that Creator was set up linked.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());

    m_connection->externalOperation(op, *m_connection);

    // BaseWorld::message should have been called from Enitty::sendWorld
    // with the Talk operation, modified to have TO set to the character.
    ASSERT_TRUE(m_BaseWorld_message_called.isValid());
    ASSERT_EQUAL(m_BaseWorld_message_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_BaseWorld_message_called->isDefaultTo());
    ASSERT_EQUAL(m_BaseWorld_message_called->getTo(), m_creator->getId());
    ASSERT_NOT_NULL(m_BaseWorld_message_called_from);
    ASSERT_EQUAL(m_BaseWorld_message_called_from, m_creator);
}
void Link::send(const Operation & op) const
{
    stub_link_send_op = op->getClassNo();
    ++stub_link_send_count;
}
Example #17
0
void Account::operation(const Operation & op, OpVector & res)
{
    if (op->getClassNo() == Atlas::Objects::Operation::LOGOUT_NO) {
        this->LogoutOperation(op, res);
    }
}
Example #18
0
void Flusher::operation(const Operation & op, OpVector & res)
{
    shared_ptr<ObjectContext> flush_context = m_context.lock();

    if (!flush_context) {
        m_complete = true;
        return;
    }

    if (op->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
        // We have a sight op, check if its the sight of an entity we
        // want to delete.
        const std::vector<Root> & args = op->getArgs();
        if (args.empty()) {
            std::cerr << "Got empty sight" << std::endl << std::flush;
            return;
        }
        const Root & arg = args.front();
        assert(arg.isValid());
        RootEntity sight_ent = smart_dynamic_cast<RootEntity>(arg);
        if (!sight_ent.isValid()) {
            return;
        }
        if (!sight_ent->hasAttrFlag(Atlas::Objects::ID_FLAG)) {
            std::cerr << "Got sight no ID" << std::endl << std::flush;
            return;
        }
        if (!sight_ent->hasAttrFlag(Atlas::Objects::PARENTS_FLAG)) {
            std::cerr << "Got sight no PARENTS" << std::endl << std::flush;
            return;
        }
        if (sight_ent->getParents().empty() ||
                sight_ent->getParents().front() != type) {
            return;
        }
        const std::string & id = sight_ent->getId();

        std::cout << "Deleting: " << type << "(" << id << ")"
                  << std::endl << std::flush;

        // Send a delete to the entity we have seen.
        Delete d;

        Anonymous dmap;
        dmap->setId(id);
        d->setArgs1(dmap);

        flush_context->setFromContext(d);

        d->setTo(id);

        res.push_back(d);

        // Send a tick for a short time in the future so that
        // we can look again once this entity is definitly gone.
        Tick t;

        Anonymous tick_arg;
        tick_arg->setName("flusher");

        flush_context->setFromContext(t);
        t->setTo(t->getFrom());
        t->setFutureSeconds(0.1);
        t->setArgs1(tick_arg);

        res.push_back(t);
    } else if (op->getParents().front() == "tick") {
        // We have a tick op, check if its the one we sent ourselves
        // to schedule the next look.
        if (op->getArgs().empty() ||
                op->getArgs().front()->getName() != "flusher") {
            std::cout << "Not for us" << std::endl << std::flush;
            return;
        }

        // Send another look by type.
        Look l;

        Anonymous lmap;
        lmap->setParents(std::list<std::string>(1, type));
        l->setArgs1(lmap);
        flush_context->setFromContext(l);

        res.push_back(l);
    } else if (op->getParents().front() == "unseen") {
        // We have an unseen op, which signals our last look returned
        // no results.
        m_complete = true;
    }
}
 virtual void message(const Operation & op, Entity & ent) {
     stub_baseworld_receieved_op = op->getClassNo();
 }
Example #20
0
/// \brief Find and call the handler for an operation
///
/// @param op The operation to be processed.
/// @param res The result of the operation is returned here.
void Entity::callOperation(const Operation & op, OpVector & res)
{
    auto op_no = op->getClassNo();
    OP_SWITCH(op, op_no, res,)
}