Skip to content

Commit

Permalink
Merge pull request #7 from kbengine/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
jay602 committed Feb 15, 2019
2 parents 000bc42 + d30a5da commit 50a1a66
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 23 deletions.
Expand Up @@ -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):
"""
Expand Down
32 changes: 31 additions & 1 deletion kbe/src/lib/entitydef/common.cpp
Expand Up @@ -7,8 +7,8 @@
namespace KBEngine{

ENTITYFLAGMAP g_entityFlagMapping;
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
std::string entityDataFlagsToString(uint32 flags)
{
if(flags == ED_FLAG_CELL_PUBLIC)
Expand Down Expand Up @@ -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<std::wstring, std::wstring> getComponentPythonPaths(COMPONENT_TYPE componentType)
{
Expand Down
1 change: 1 addition & 0 deletions kbe/src/lib/entitydef/common.h
Expand Up @@ -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 | \
Expand Down
35 changes: 30 additions & 5 deletions kbe/src/lib/entitydef/datatypes.cpp
Expand Up @@ -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()
{
Expand All @@ -34,6 +36,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)
{
Expand Down Expand Up @@ -62,19 +74,33 @@ 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)
{
TiXmlNode* node = NULL;
SmartPointer<XML> xml(new XML(Resmgr::getSingleton().matchRes(file).c_str()));
return loadTypes(xml);
}

if(xml == NULL || !xml->isGood())
//-------------------------------------------------------------------------------------
bool DataTypes::loadTypes(SmartPointer<XML>& xml)
{
if (xml == NULL || !xml->isGood())
return false;

node = xml->getRootNode();
TiXmlNode* node = xml->getRootNode();

if(node == NULL)
{
Expand All @@ -88,8 +114,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()));
Expand Down
9 changes: 7 additions & 2 deletions kbe/src/lib/entitydef/datatypes.h
Expand Up @@ -38,12 +38,17 @@ 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>& 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_;
Expand Down
6 changes: 3 additions & 3 deletions kbe/src/lib/entitydef/entitydef.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion kbe/src/lib/entitydef/entitydef.h
Expand Up @@ -166,7 +166,7 @@ class EntityDef
/**
检查脚本模块中被定义的属性是否合法
*/
static bool validDefPropertyName(ScriptDefModule* pScriptModule, const std::string& name);
static bool validDefPropertyName(const std::string& name);

/**
通过标记来寻找到对应的脚本模块对象
Expand Down
99 changes: 91 additions & 8 deletions kbe/src/lib/entitydef/py_entitydef.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -421,12 +422,57 @@ 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;
}

// 检查作用域是否属于该进程
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)
{
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())
{
Expand Down Expand Up @@ -466,6 +512,7 @@ static bool registerDefContext(DefContext& defContext)
}

//-------------------------------------------------------------------------------------

static bool onDefRename(DefContext& defContext)
{
defContext.type = DefContext::DC_TYPE_RENAME;
Expand Down Expand Up @@ -1558,6 +1605,35 @@ 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;

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;
}

//-------------------------------------------------------------------------------------
static bool registerEntityDef()
{
if (!registerDefTypes())
return false;

return true;
}

//-------------------------------------------------------------------------------------
bool initialize()
{
Expand Down Expand Up @@ -1613,17 +1689,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;
}

Expand Down

0 comments on commit 50a1a66

Please sign in to comment.