From 0557b2aff9d9a78343dc47493ed192ac4fac5124 Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Wed, 13 Feb 2019 15:47:26 +0800 Subject: [PATCH 1/7] up --- kbe/src/lib/entitydef/datatypes.cpp | 23 ++++++++++++++++++----- kbe/src/lib/entitydef/datatypes.h | 3 +++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/kbe/src/lib/entitydef/datatypes.cpp b/kbe/src/lib/entitydef/datatypes.cpp index a80965f3ff..b4766bac5e 100644 --- a/kbe/src/lib/entitydef/datatypes.cpp +++ b/kbe/src/lib/entitydef/datatypes.cpp @@ -34,6 +34,16 @@ void DataTypes::finalise(void) dataTypes_.clear(); } +//------------------------------------------------------------------------------------- +bool DataTypes::validTypeName(const std::string& typeName) +{ + // 不允许前面加_, 因为内部产生的一些临时结构前面使用了_, 避免误判 + if (typeName.size() > 0 && typeName[0] == '_') + return false; + + return true; +} + //------------------------------------------------------------------------------------- bool DataTypes::initialize(std::string file) { @@ -68,13 +78,17 @@ bool DataTypes::initialize(std::string file) //------------------------------------------------------------------------------------- bool DataTypes::loadTypes(std::string& file) { - TiXmlNode* node = NULL; SmartPointer xml(new XML(Resmgr::getSingleton().matchRes(file).c_str())); + return loadTypes(xml); +} - if(xml == NULL || !xml->isGood()) +//------------------------------------------------------------------------------------- +bool DataTypes::loadTypes(SmartPointer& xml) +{ + if (xml == NULL || !xml->isGood()) return false; - node = xml->getRootNode(); + TiXmlNode* node = xml->getRootNode(); if(node == NULL) { @@ -88,8 +102,7 @@ bool DataTypes::loadTypes(std::string& file) std::string aliasName = xml->getKey(node); TiXmlNode* childNode = node->FirstChild(); - // 不允许前面加_, 因为内部产生的一些临时结构前面使用了_, 避免误判 - if (aliasName[0] == '_') + if (!DataTypes::validTypeName(aliasName)) { ERROR_MSG(fmt::format("DataTypes::loadTypes: Not allowed to use the prefix \"_\"! aliasName={}\n", aliasName.c_str())); diff --git a/kbe/src/lib/entitydef/datatypes.h b/kbe/src/lib/entitydef/datatypes.h index 26a7eeb4cd..59054d33ba 100644 --- a/kbe/src/lib/entitydef/datatypes.h +++ b/kbe/src/lib/entitydef/datatypes.h @@ -38,7 +38,10 @@ class DataTypes static DataType* getDataType(const char* name, bool notFoundOutError = true); static DataType* getDataType(DATATYPE_UID uid); + static bool validTypeName(const std::string& typeName); + static bool loadTypes(std::string& file); + static bool loadTypes(SmartPointer& xml); static const DATATYPE_MAP& dataTypes(){ return dataTypes_; } static const UID_DATATYPE_MAP& uid_dataTypes(){ return uid_dataTypes_; } From d7b5f85707b58fd683847816feb94e76f300506d Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Wed, 13 Feb 2019 16:41:21 +0800 Subject: [PATCH 2/7] up --- kbe/src/lib/entitydef/entitydef.cpp | 6 +++--- kbe/src/lib/entitydef/entitydef.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kbe/src/lib/entitydef/entitydef.cpp b/kbe/src/lib/entitydef/entitydef.cpp index c63a15f166..4736df1adc 100644 --- a/kbe/src/lib/entitydef/entitydef.cpp +++ b/kbe/src/lib/entitydef/entitydef.cpp @@ -574,7 +574,7 @@ bool EntityDef::loadComponents(const std::string& defFilePath, if (!componentNode) continue; - if (!validDefPropertyName(pScriptModule, componentName)) + if (!validDefPropertyName(componentName)) { ERROR_MSG(fmt::format("EntityDef::loadComponents: '{}' is limited, in module({})!\n", componentName, moduleName)); @@ -880,7 +880,7 @@ bool EntityDef::loadAllDefDescriptions(const std::string& moduleName, } //------------------------------------------------------------------------------------- -bool EntityDef::validDefPropertyName(ScriptDefModule* pScriptModule, const std::string& name) +bool EntityDef::validDefPropertyName(const std::string& name) { int i = 0; @@ -1039,7 +1039,7 @@ bool EntityDef::loadDefPropertys(const std::string& moduleName, std::string name = ""; name = xml->getKey(defPropertyNode); - if(!validDefPropertyName(pScriptModule, name)) + if(!validDefPropertyName(name)) { ERROR_MSG(fmt::format("EntityDef::loadDefPropertys: '{}' is limited, in module({})!\n", name, moduleName)); diff --git a/kbe/src/lib/entitydef/entitydef.h b/kbe/src/lib/entitydef/entitydef.h index b82b4c1d69..f016ffd1bc 100644 --- a/kbe/src/lib/entitydef/entitydef.h +++ b/kbe/src/lib/entitydef/entitydef.h @@ -166,7 +166,7 @@ class EntityDef /** 检查脚本模块中被定义的属性是否合法 */ - static bool validDefPropertyName(ScriptDefModule* pScriptModule, const std::string& name); + static bool validDefPropertyName(const std::string& name); /** 通过标记来寻找到对应的脚本模块对象 From bcfbb9cb451e8fbcf8a20e489de730fcadefa3f9 Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Wed, 13 Feb 2019 16:51:04 +0800 Subject: [PATCH 3/7] Update py_entitydef.cpp --- kbe/src/lib/entitydef/py_entitydef.cpp | 74 +++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/kbe/src/lib/entitydef/py_entitydef.cpp b/kbe/src/lib/entitydef/py_entitydef.cpp index d9f93cc2f5..1b74179f37 100644 --- a/kbe/src/lib/entitydef/py_entitydef.cpp +++ b/kbe/src/lib/entitydef/py_entitydef.cpp @@ -6,6 +6,7 @@ #include "common.h" #include "entitydef.h" +#include "datatypes.h" #include "py_entitydef.h" #include "pyscript/py_platform.h" #include "pyscript/pyobject_pointer.h" @@ -421,11 +422,39 @@ static bool registerDefContext(DefContext& defContext) std::string name = defContext.moduleName; - if (defContext.type == DefContext::DC_TYPE_PROPERTY || - defContext.type == DefContext::DC_TYPE_METHOD || - defContext.type == DefContext::DC_TYPE_CLIENT_METHOD || - defContext.type == DefContext::DC_TYPE_FIXED_ITEM) + if (defContext.type == DefContext::DC_TYPE_PROPERTY) + { + if(!EntityDef::validDefPropertyName(name)) + { + PyErr_Format(PyExc_AssertionError, "Def.%s: '%s' is limited!\n\n", + defContext.optionName.c_str(), name.c_str()); + + return false; + } + + name += "." + defContext.attrName; + } + else if(defContext.type == DefContext::DC_TYPE_METHOD || + defContext.type == DefContext::DC_TYPE_CLIENT_METHOD) + { + name += "." + defContext.attrName; + } + else if (defContext.type == DefContext::DC_TYPE_FIXED_ITEM) + { name += "." + defContext.attrName; + } + else if (defContext.type == DefContext::DC_TYPE_FIXED_ARRAY || + defContext.type == DefContext::DC_TYPE_FIXED_DICT || + defContext.type == DefContext::DC_TYPE_RENAME) + { + if (!DataTypes::validTypeName(name)) + { + PyErr_Format(PyExc_AssertionError, "Def.%s: Not allowed to use the prefix \"_\"! typeName=%s\n", + defContext.optionName.c_str(), name.c_str()); + + return false; + } + } DEF_CONTEXT_MAP::iterator iter = g_allScriptDefContextMaps.find(name); if (iter != g_allScriptDefContextMaps.end()) @@ -466,6 +495,7 @@ static bool registerDefContext(DefContext& defContext) } //------------------------------------------------------------------------------------- + static bool onDefRename(DefContext& defContext) { defContext.type = DefContext::DC_TYPE_RENAME; @@ -1558,6 +1588,27 @@ static bool loadAllScripts() return true; } +//------------------------------------------------------------------------------------- +static bool registerDefTypes() +{ + DEF_CONTEXT_MAP::iterator iter = g_allScriptDefContextMaps.begin(); + for (; iter != g_allScriptDefContextMaps.end(); ++iter) + { + DefContext& defContext = iter->second; + } + + return true; +} + +//------------------------------------------------------------------------------------- +static bool registerEntityDef() +{ + if (!registerDefTypes()) + return false; + + return true; +} + //------------------------------------------------------------------------------------- bool initialize() { @@ -1613,17 +1664,24 @@ bool initialize() return false; } + while (!g_callContexts.empty()) + g_callContexts.pop(); + + g_allScriptDefContextLineMaps.clear(); + if (!assemblyContexts(true)) { SCRIPT_ERROR_CHECK(); + g_allScriptDefContextMaps.clear(); return false; } - while (!g_callContexts.empty()) - g_callContexts.pop(); + if (!registerEntityDef()) + { + g_allScriptDefContextMaps.clear(); + return false; + } - g_allScriptDefContextMaps.clear(); - g_allScriptDefContextLineMaps.clear(); return true; } From 866fbd02b4fde47480aa5f135a4a30c61920ce0f Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Wed, 13 Feb 2019 17:24:43 +0800 Subject: [PATCH 4/7] Update Poller.py --- .../server/python_assets/scripts/interface/Poller.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kbe/res/sdk_templates/server/python_assets/scripts/interface/Poller.py b/kbe/res/sdk_templates/server/python_assets/scripts/interface/Poller.py index 8f3318457b..209ac2f113 100644 --- a/kbe/res/sdk_templates/server/python_assets/scripts/interface/Poller.py +++ b/kbe/res/sdk_templates/server/python_assets/scripts/interface/Poller.py @@ -54,11 +54,16 @@ def onRecv(self, fileno): return data = sock.recv(2048) + + if len(data) == 0: + DEBUG_MSG("Poller::onRecv: %s/%i disconnect!" % (addr, sock.fileno())) + KBEngine.deregisterReadFileDescriptor(sock.fileno()) + sock.close() + del self._clients[fileno] + return + DEBUG_MSG("Poller::onRecv: %s/%i get data, size=%i" % (addr, sock.fileno(), len(data))) self.processData(sock, data) - KBEngine.deregisterReadFileDescriptor(sock.fileno()) - sock.close() - del self._clients[fileno] def processData(self, sock, datas): """ From 9ae92c5e0fd9991eefe724ecc3cdffb8ec3885dd Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Thu, 14 Feb 2019 13:40:36 +0800 Subject: [PATCH 5/7] up --- kbe/src/lib/entitydef/common.cpp | 32 +++++++++++++++++++++++++++++++- kbe/src/lib/entitydef/common.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/kbe/src/lib/entitydef/common.cpp b/kbe/src/lib/entitydef/common.cpp index 355aa7bb1b..0890decad2 100644 --- a/kbe/src/lib/entitydef/common.cpp +++ b/kbe/src/lib/entitydef/common.cpp @@ -7,8 +7,8 @@ namespace KBEngine{ ENTITYFLAGMAP g_entityFlagMapping; -//------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- std::string entityDataFlagsToString(uint32 flags) { if(flags == ED_FLAG_CELL_PUBLIC) @@ -38,6 +38,36 @@ std::string entityDataFlagsToString(uint32 flags) return "UNKOWN"; } +//------------------------------------------------------------------------------------- +EntityDataFlags stringToEntityDataFlags(const std::string& strFlags) +{ + if (strFlags == "CELL_PUBLIC") + return ED_FLAG_CELL_PUBLIC; + + if (strFlags == "CELL_PRIVATE") + return ED_FLAG_CELL_PRIVATE; + + if (strFlags == "ALL_CLIENTS") + return ED_FLAG_ALL_CLIENTS; + + if (strFlags == "CELL_PUBLIC_AND_OWN") + return ED_FLAG_CELL_PUBLIC_AND_OWN; + + if (strFlags == "OWN_CLIENT") + return ED_FLAG_OWN_CLIENT; + + if (strFlags == "BASE_AND_CLIENT") + return ED_FLAG_BASE_AND_CLIENT; + + if (strFlags == "BASE") + return ED_FLAG_BASE; + + if (strFlags == "OTHER_CLIENTS") + return ED_FLAG_OTHER_CLIENTS; + + return ED_FLAG_UNKOWN; +} + //------------------------------------------------------------------------------------- std::pair getComponentPythonPaths(COMPONENT_TYPE componentType) { diff --git a/kbe/src/lib/entitydef/common.h b/kbe/src/lib/entitydef/common.h index f734b8fa2e..6ddad94cf2 100644 --- a/kbe/src/lib/entitydef/common.h +++ b/kbe/src/lib/entitydef/common.h @@ -28,6 +28,7 @@ enum EntityDataFlags }; std::string entityDataFlagsToString(uint32 flags); +EntityDataFlags stringToEntityDataFlags(const std::string& strFlags); #define ED_FLAG_ALL ED_FLAG_CELL_PUBLIC | ED_FLAG_CELL_PRIVATE | ED_FLAG_ALL_CLIENTS \ | ED_FLAG_CELL_PUBLIC_AND_OWN | ED_FLAG_OWN_CLIENT | \ From a4a391bc9e16994eaf35cea5323f8c33018c1fd1 Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Thu, 14 Feb 2019 13:40:46 +0800 Subject: [PATCH 6/7] Update py_entitydef.cpp --- kbe/src/lib/entitydef/py_entitydef.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/kbe/src/lib/entitydef/py_entitydef.cpp b/kbe/src/lib/entitydef/py_entitydef.cpp index 1b74179f37..726c843768 100644 --- a/kbe/src/lib/entitydef/py_entitydef.cpp +++ b/kbe/src/lib/entitydef/py_entitydef.cpp @@ -432,7 +432,24 @@ static bool registerDefContext(DefContext& defContext) return false; } + // 检查作用域是否属于该进程 + bool flagsGood = true; + if (defContext.componentType == BASEAPP_TYPE) + flagsGood = (stringToEntityDataFlags(defContext.propertyFlags) & ENTITY_BASE_DATA_FLAGS) != 0; + else if (defContext.componentType == CELLAPP_TYPE) + flagsGood = (stringToEntityDataFlags(defContext.propertyFlags) & ENTITY_CELL_DATA_FLAGS) != 0; + else if (defContext.componentType == CLIENT_TYPE) + flagsGood = (stringToEntityDataFlags(defContext.propertyFlags) & ENTITY_CLIENT_DATA_FLAGS) != 0; + name += "." + defContext.attrName; + + if (!flagsGood) + { + PyErr_Format(PyExc_AssertionError, "Def.%s: '%s'(%s) not a valid %s property flags!\n\n", + defContext.optionName.c_str(), name.c_str(), defContext.propertyFlags.c_str(), COMPONENT_NAME_EX(defContext.componentType)); + + return false; + } } else if(defContext.type == DefContext::DC_TYPE_METHOD || defContext.type == DefContext::DC_TYPE_CLIENT_METHOD) @@ -1595,6 +1612,14 @@ static bool registerDefTypes() for (; iter != g_allScriptDefContextMaps.end(); ++iter) { DefContext& defContext = iter->second; + + if (defContext.type != DefContext::DC_TYPE_FIXED_ARRAY && + defContext.type != DefContext::DC_TYPE_FIXED_DICT && + defContext.type != DefContext::DC_TYPE_RENAME) + continue; + + int i = 0; + i++; } return true; From d30a5da34b409f35e9f7e6f02efaf21c26d31e6c Mon Sep 17 00:00:00 2001 From: kebiao <380000937@qq.com> Date: Fri, 15 Feb 2019 15:23:11 +0800 Subject: [PATCH 7/7] up --- kbe/src/lib/entitydef/datatypes.cpp | 12 ++++++++++++ kbe/src/lib/entitydef/datatypes.h | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/kbe/src/lib/entitydef/datatypes.cpp b/kbe/src/lib/entitydef/datatypes.cpp index b4766bac5e..afb3ac0548 100644 --- a/kbe/src/lib/entitydef/datatypes.cpp +++ b/kbe/src/lib/entitydef/datatypes.cpp @@ -11,6 +11,8 @@ DataTypes::DATATYPE_MAP DataTypes::dataTypesLowerName_; DataTypes::UID_DATATYPE_MAP DataTypes::uid_dataTypes_; DataTypes::DATATYPE_ORDERS DataTypes::dataTypesOrders_; +static uint8 _g_baseTypeEndIndex = 0; + //------------------------------------------------------------------------------------- DataTypes::DataTypes() { @@ -72,9 +74,19 @@ bool DataTypes::initialize(std::string file) addDataType("VECTOR2", new Vector2Type); addDataType("VECTOR3", new Vector3Type); addDataType("VECTOR4", new Vector4Type); + + _g_baseTypeEndIndex = dataTypesOrders_.size(); return loadTypes(file); } +//------------------------------------------------------------------------------------- +std::vector< std::string > DataTypes::getBaseTypeNames() +{ + std::vector< std::string > ret; + ret.assign(dataTypesOrders_.begin(), dataTypesOrders_.begin() + _g_baseTypeEndIndex); + return ret; +} + //------------------------------------------------------------------------------------- bool DataTypes::loadTypes(std::string& file) { diff --git a/kbe/src/lib/entitydef/datatypes.h b/kbe/src/lib/entitydef/datatypes.h index 59054d33ba..621c8af328 100644 --- a/kbe/src/lib/entitydef/datatypes.h +++ b/kbe/src/lib/entitydef/datatypes.h @@ -43,10 +43,12 @@ class DataTypes static bool loadTypes(std::string& file); static bool loadTypes(SmartPointer& xml); - static const DATATYPE_MAP& dataTypes(){ return dataTypes_; } - static const UID_DATATYPE_MAP& uid_dataTypes(){ return uid_dataTypes_; } + static const DATATYPE_MAP& dataTypes() { return dataTypes_; } + static const UID_DATATYPE_MAP& uid_dataTypes() { return uid_dataTypes_; } static const DATATYPE_ORDERS& dataTypesOrders() { return dataTypesOrders_; } + static std::vector< std::string > getBaseTypeNames(); + protected: static DATATYPE_MAP dataTypes_; static DATATYPE_MAP dataTypesLowerName_;