예제 #1
0
void ServerInfo::processServer(const RootEntity &svr)
{
    Atlas::Message::Element element;

    if (!svr->copyAttr("ruleset", element) && element.isString()) {
        _ruleset = element.asString();
    } else {
        return;
    }

    _name = svr->getName();
    if (!svr->copyAttr("clients", element) && element.isInt()) {
        _clients = element.asInt();
    } else {
        return;
    }
    if (!svr->copyAttr("server", element) && element.isString()) {
        _server = element.asString();
    } else {
        return;
    }
    if (!svr->copyAttr("uptime", element) && element.isFloat()) {
        _uptime = element.asFloat();
    } else {
        return;
    }

    m_status = VALID;

    if (!svr->copyAttr("entities", element) && element.isInt()) {
        _entities = element.asInt();
    }
    
    if (!svr->copyAttr("version", element) && element.isString()) {
        m_version = element.asString();
    }
    
    if (!svr->copyAttr("builddate", element) && element.isString()) {
        m_buildDate = element.asString();
    }
}
예제 #2
0
void StaticAdapter::updateGui(const ::Atlas::Message::Element& element)
{
	SelfUpdateContext context(*this);
	
	if (mTextWindow) {
		if (element.isString()) {
			mTextWindow->setText(element.asString());
		} else if (element.isNum()) {
			std::stringstream ss;
			ss << element.asNum();
			mTextWindow->setText(ss.str());
		}
	}
}
예제 #3
0
void EmberEntity::onImaginary(const Atlas::Objects::Root& act)
{
  Atlas::Message::Element attr;
  if (act->copyAttr("description", attr) && attr.isString()) {
    std::string message = getName() + " " + attr.asString() + ".";

    ConsoleBackend::getSingletonPtr()->pushMessage(message, "info");

    S_LOG_VERBOSE("Entity: " << this->getId() << " (" << this->getName() << ") imaginary: " << attr.String());
  }

  Entity::onImaginary(act);

}
예제 #4
0
파일: EmberEntity.cpp 프로젝트: Laefy/ember
void EmberEntity::parsePositioningModeChange(const Atlas::Message::Element& v)
{
	const std::string& mode = v.asString();
	PositioningMode newMode;
	if (mode.empty()) {
		newMode = PM_DEFAULT;
	} else if (mode == MODE_FLOATING) {
		newMode = PM_FLOATING;
	} else if (mode == MODE_FIXED) {
		newMode = PM_FIXED;
	} else if (mode == MODE_PROJECTILE) {
		newMode = PM_PROJECTILE;
	} else if (mode == MODE_SWIMMING) {
		newMode = PM_SWIMMING;
	} else {
		newMode = PM_DEFAULT;
	}

	onPositioningModeChanged(newMode);
}
예제 #5
0
void EntityImporterBase::errorArrived(const Operation & op, OpVector & res)
{
    std::string errorMessage;
    if (!op->getArgs().empty()) {
        auto arg = op->getArgs().front();
        if (arg->hasAttr("message")) {
            const Atlas::Message::Element messageElem = arg->getAttr("message");
            if (messageElem.isString()) {
                errorMessage = messageElem.asString();
            }
        }
    }

    switch (m_state) {
    case RULE_WALKING:
    {
        //An error here just means that the rule we asked for didn't exist on the server, and we need
        //to create it. This is an expected result.
        auto& current = mRuleStack.back();
        auto definition = current.definition;
        assert(definition.isValid());

        createRule(definition, res);

    }
        break;
    case RULE_CREATING:
    {
        mStats.rulesProcessedCount++;
        mStats.rulesCreateErrorCount++;
        //An error here means that something went wrong when trying to create a rule. This is wrong.
        //It probably means that there's something wrong with the data we're sending.
        auto& current = mRuleStack.back();

        std::string ruleId = current.definition->getId();
        S_LOG_FAILURE("Could not create rule with id '" << ruleId << "', continuing with next. Server message: " << errorMessage);
        EventProgress.emit();
        walkRules(res);
    }
        break;
    case RULE_UPDATING:
    {
        mStats.rulesProcessedCount++;
        //An error here means that something went wrong when trying to update a rule. This is wrong.
        //It probably means that there's something wrong with the data we're sending.
        auto& current = mRuleStack.back();

        std::string ruleId = current.definition->getId();
        S_LOG_FAILURE("Could not update rule with id '" << ruleId << "', continuing with next. Server message: " << errorMessage);
        mStats.rulesCreateErrorCount++;
        EventProgress.emit();
        walkRules(res);
    }
        break;
    case ENTITY_WALKING:
    {
        //An error here just means that the entity we asked for didn't exist on the server, and we need
        //to create it. This is an expected result.
        assert(!mTreeStack.empty());
        StackEntry & current = mTreeStack.back();
        const RootEntity& obj = current.obj;

        assert(obj.isValid());

        createEntity(obj, res);
    }
        break;
    case ENTITY_CREATING:
    {
        //An error here means that something went wrong when trying to create an entity. This is wrong.
        //It probably means that there's something wrong with the data we're sending. Either the
        //persisted data is corrupt, or there have been changes on the server (for example entity types
        //renamed or removed).
        std::string entityType = "unknown";

        auto I = mCreateEntityMapping.find(op->getRefno());
        if (I != mCreateEntityMapping.end()) {
            auto J = mPersistedEntities.find(I->second);
            if (J != mPersistedEntities.end()) {
                auto& entity = J->second;
                entityType = entity->getParent();
            }
        }
        S_LOG_FAILURE("Could not create entity of type '" << entityType << "', continuing with next. Server message: " << errorMessage);
        mStats.entitiesCreateErrorCount++;
        EventProgress.emit();
        walkEntities(res);
    }
        break;
    default:
        S_LOG_FAILURE("Unexpected state in state machine: " << m_state << ". Server message: " << errorMessage);
        break;
    };
}