コード例 #1
0
/**
 * @brief Ctor.
 */
TerrainModTranslator::TerrainModTranslator(const Atlas::Message::MapType& data) :
		mInnerTranslator(nullptr)
{

	MapType::const_iterator I = data.find("type");
	if (I == data.end() || !I->second.isString()) {
		return;
	}
	const std::string& modType = I->second.String();

	I = data.find("shape");
	if (I == data.end() || !I->second.isMap()) {
		return;
	}
	const MapType& shapeMap = I->second.Map();

	// Get shape's type
	I = shapeMap.find("type");
	if (I == shapeMap.end() || !I->second.isString()) {
		return;
	}
	const std::string& shapeType = I->second.String();
	if (shapeType == "ball") {
		WFMath::Ball<2> shape;
		mInnerTranslator.reset(buildTranslator(data, modType, shape, shapeMap));
	} else if (shapeType == "rotbox") {
		WFMath::RotBox<2> shape;
		mInnerTranslator.reset(buildTranslator(data, modType, shape, shapeMap));
	} else if (shapeType == "polygon") {
		WFMath::Polygon<2> shape;
		mInnerTranslator.reset(buildTranslator(data, modType, shape, shapeMap));
	}
}
コード例 #2
0
ファイル: Storage.cpp プロジェクト: erikogenvik/cyphesis
/// \brief Modify the attributes of an Account in the database
///
/// @param account Atlas description of the Account to be modified
/// @param accountId String identifier of the Account to be modified
bool Storage::modAccount(const Atlas::Message::MapType & account,
                         const std::string & accountId)
{
    std::string columns;
    bool empty = true;

    Atlas::Message::MapType::const_iterator I = account.find("type");
    if (I != account.end() && I->second.isString()) {
        empty = false;
        columns += "type = '";
        columns += I->second.String();
        columns += "'";
    }

    I = account.find("password");
    if (I != account.end() && I->second.isString()) {
        if (!empty) { columns += ", "; }
        std::string hash;
        encrypt_password(I->second.String(), hash);
        columns += "password = '******'";
    }
    return m_connection.updateSimpleRow("accounts", "username",
                                        accountId, columns);
}
コード例 #3
0
ファイル: RuleHandler.cpp プロジェクト: 9cat/cyphesis
int RuleHandler::getScriptDetails(const Atlas::Message::MapType & script,
                                  const std::string & class_name,
                                  const std::string & context,
                                  std::string & script_package,
                                  std::string & script_class)
{
    MapType::const_iterator J = script.find("name");
    MapType::const_iterator Jend = script.end();

    if (J == Jend || !J->second.isString()) {
        log(ERROR, compose("%1 \"%2\" script has no name.",
                           context, class_name));
        return -1;
    }
    const std::string & script_name = J->second.String();
    J = script.find("language");
    if (J == Jend || !J->second.isString()) {
        log(ERROR, compose("%1 \"%2\" script has no language.",
                           context, class_name));
        return -1;
    }
    const std::string & script_language = J->second.String();
    if (script_language != "python") {
        log(ERROR, compose("%1 \"%2\" script has unknown language \"%3\".",
                           context, class_name, script_language));
        return -1;
    }
    std::string::size_type ptr = script_name.rfind(".");
    if (ptr == std::string::npos) {
        log(ERROR, compose("%1 \"%2\" python script has bad class name \"%3\".",
                           context, class_name, script_name));
        return -1;
    }
    script_package = script_name.substr(0, ptr);
    script_class = script_name.substr(ptr + 1);

    return 0;
}
コード例 #4
0
ファイル: Storage.cpp プロジェクト: erikogenvik/cyphesis
/// \brief Store a new Account in the database
///
/// @param account Atlas description of Account to be stored
bool Storage::putAccount(const Atlas::Message::MapType & account)
{
    Atlas::Message::MapType::const_iterator I = account.find("username");
    if (I == account.end() || !I->second.isString()) {
        return false;
    }
    const std::string & username = I->second.String();
    
    I = account.find("password");
    if (I == account.end() || !I->second.isString()) {
        return false;
    }
    const std::string & password = I->second.String();
    std::string hash;
    encrypt_password(password, hash);
    
    std::string type = "player";
    I = account.find("type");
    if (I != account.end() && I->second.isString()) {
        type = I->second.String();
    }
    
    std::string columns = "username, type, password";
    std::string values = "'";
    values += username;
    values += "', '";
    values += type;
    values += "', '";
    values += hash;
    values += "'";

    std::string id;
    if (m_connection.newId(id) < 0) {
        return false;
    }
    return m_connection.createSimpleRow("accounts", id, columns, values);
}
コード例 #5
0
ファイル: EntityRecipe.cpp プロジェクト: angkorcn/ember
Atlas::Message::MapType EntityRecipe::createEntity(Eris::TypeService& typeService)
{
	S_LOG_VERBOSE("Creating entity.");

	ScriptingService& scriptingService = EmberServices::getSingleton().getScriptingService();
	// Loading script code
	scriptingService.executeCode(mScript, "LuaScriptingProvider");

	// Walking through adapter bindings
	for (BindingsStore::iterator I = mBindings.begin(); I != mBindings.end(); ++I) {
		const std::string& func = I->second->getFunc();

		S_LOG_VERBOSE(" binding: " << I->first << " to func " << func);

		if (func.empty()) {
			std::vector<std::string>& adapters = I->second->getAdapters();

			if (adapters.size() == 1) {
				std::string adapterName = adapters[0];
				Atlas::Message::Element val = mGUIAdapters[adapterName]->getValue();
				I->second->setValue(val);
			} else {
				S_LOG_WARNING("Should be only one adapter without calling function.");
			}
		} else {
			Lua::LuaScriptingCallContext callContext;

			lua_State* L = static_cast<Lua::LuaScriptingProvider*> (scriptingService.getProviderFor("LuaScriptingProvider"))->getLuaState();

			// Pushing function params
			std::vector<std::string>& adapters = I->second->getAdapters();
			for (std::vector<std::string>::iterator J = adapters.begin(); J != adapters.end(); J++) {
				std::string adapterName = *J;
				Atlas::Message::Element* val = new Atlas::Message::Element(mGUIAdapters[adapterName]->getValue());
				tolua_pushusertype_and_takeownership(L, val, "Atlas::Message::Element");
			}

			// Calling test function
			scriptingService.callFunction(func, adapters.size(), "LuaScriptingProvider", &callContext);

			LuaRef returnValue(callContext.getReturnValue());

			Atlas::Message::Element returnObj;
			returnObj = returnValue.asObject<Atlas::Message::Element> ("Atlas::Message::Element");
			I->second->setValue(returnObj);
		}
	}
	//Inject all default attributes that aren't yet added.
	// 	TiXmlElement *elem = mEntitySpec->FirstChildElement("atlas");
	// 	if (elem)
	// 	{
	// 		Eris::TypeInfo* erisType = mConn->getTypeService()->getTypeByName(getEntityType());
	// 		if (erisType) {
	// 			const Atlas::Message::MapType& defaultAttributes = erisType->getAttributes();
	// 			for (Atlas::Message::MapType::const_iterator I = defaultAttributes.begin(); I != defaultAttributes.end(); ++I) {
	// 				bool hasAttribute = false;
	// 				TiXmlNode* child(0);
	// 				while(child = elem->IterateChildren(child)) {
	// 					if (child->ToElement()) {
	// 						if (std::string(child->ToElement()->Attribute("name")) == I->first) {
	// 							hasAttribute = true;
	// 							break;
	// 						}
	// 					}
	// 				}
	//
	// 				if (!hasAttribute) {
	// 					//The attribute isn't present, we'll inject it
	// 					//This a bit contrived, since we'll now first convert the atlas into xml and inject it into the TiXmlElement (which will convert the xml strings into TiXml structures). And then later on we'll parse the xml again and create the final atlas data from it. However, the main reason for doing it this way is that in the future we would want to have nested child elements, which could be repeated. And in those cases we'll want to work directly with xml.
	// 				}
	// 			}
	// 		}
	// 	}
	/*
	 std::stringstream str;

	 Atlas::Message::Element element(message);

	 Atlas::Message::QueuedDecoder decoder;

	 Atlas::Codecs::XML codec(str, decoder);
	 Atlas::Formatter formatter(str, codec);
	 Atlas::Message::Encoder encoder(formatter);
	 formatter.streamBegin();
	 encoder.streamMessageElement(message);
	 formatter.streamEnd();
	 */
	if (mEntitySpec) {
		// Print entity into string
		TiXmlPrinter printer;
		printer.SetStreamPrinting();
		mEntitySpec->Accept(&printer);

		S_LOG_VERBOSE("Composed entity: " << printer.Str());

		std::stringstream strStream(printer.CStr(), std::ios::in);

		// Create objects
		Atlas::Message::QueuedDecoder decoder;
		Atlas::Codecs::XML codec(strStream, decoder);

		// Read whole stream into decoder queue
		while (!strStream.eof()) {
			codec.poll();
		}

		// Read decoder queue
		while (decoder.queueSize() > 0) {
			Atlas::Message::MapType m = decoder.popMessage();
			Eris::TypeInfo* erisType = typeService.getTypeByName(getEntityType());
			if (erisType) {
				const Atlas::Message::MapType& defaultAttributes = erisType->getAttributes();
				for (Atlas::Message::MapType::const_iterator I = defaultAttributes.begin(); I != defaultAttributes.end(); ++I) {
					if (m.find(I->first) == m.end()) {
						m.insert(Atlas::Message::MapType::value_type(I->first, I->second));
					}
				}
			}
			return m;
		}
	} else {
		Atlas::Message::MapType msg;
		msg["parents"] = Atlas::Message::ListType(1, mEntityType);
		msg["name"] = getName();
		return msg;
	}
	S_LOG_WARNING("No entity composed");
	return Atlas::Message::MapType();
}