Example #1
0
// 初始化属性配置
void CEntityGroup::InitProperty()
{
	CEntityManager::AttrDefMap& mapAttrDef = GetGame()->GetEntityManager()->GetObjAttrDef();
	CEntityManager::AttrDefMapItr itr = mapAttrDef.find(GetCompositeFlag());
	if(itr != mapAttrDef.end())
	{
		// 初始化属性变量
		tagEntityBuildInfo* pInfo = itr->second;
		if(!pInfo) return;
		
		map<string, tagEntityAttrInfo>::iterator daEpItr = itr->second->pDataMgr.begin();
		for(; daEpItr != itr->second->pDataMgr.end(); daEpItr++)
		{
			m_DataEntityManager.CreateEntityProperty(daEpItr->second.lAttrTypeEnum);
		}

		// 初始化数据
		m_lLeafComFlag = pInfo->strLeafComFlag;
		m_lLeafComType = pInfo->lLeafComType;
		m_bHasDetailLeavesFlag = pInfo->lHasDetailLeaves;

		m_CompositeType = (COMPOSITE_TYPE)pInfo->lComType;
		m_bHasAttrs = pInfo->lHhasAttrFlag;

		m_strDetailComPositeFlagName = pInfo->strDbQueryName;
		m_lDetailComPositeFlagType = pInfo->lDbQueryType;

		if(m_lDetailComPositeFlagType != -1) // 有分散类型
		{
			long lQueryAttrType = GetGame()->GetEntityManager()->GetAttrEnumByStr(pInfo->strComFlag, pInfo->strDbQueryName);

			CEntityProperty* pEP = m_DataEntityManager.CreateEntityProperty(lQueryAttrType);
			if(pEP)
			{
				switch((DATA_OBJECT_TYPE)pInfo->lDbQueryType)
				{
				case DATA_OBJECT_TIME:
					{
						pEP->SetBufAttr(((void*)&pInfo->pQueryVar[0]), 6*sizeof(DWORD));
					}
					break;
				case  DATA_OBJECT_STRING:
					{
						pEP->SetStringAttr(string((char*)&pInfo->pQueryVar[0]));
					}
					break;
				case DATA_OBJECT_BUFFER:
					{
						pEP->SetBufAttr(((void*)&pInfo->pQueryVar[0]), 6*sizeof(DWORD));
					}
					break;
				case DATA_OBJECT_GUID:
					{
						CGUID bguid;
						memcpy(&bguid, pInfo->pQueryVar, sizeof(CGUID));
						pEP->SetGuidAttr(bguid);
					}
					break;
				case DATA_OBJECT_BOOL:
				case DATA_OBJECT_CHAR:
				case DATA_OBJECT_BYTE:
				case DATA_OBJECT_SHORT:
				case DATA_OBJECT_WORD:
				case DATA_OBJECT_USHORT:
				case DATA_OBJECT_FLOAT:
				case DATA_OBJECT_LONG:
				case DATA_OBJECT_ULONG:
				case DATA_OBJECT_DWORD:
					{
						long lVar = *((long*)&pInfo->pQueryVar[0]);
						pEP->SetLongAttr(lVar);
					}
					break;
				}
			}
		}
		// 初始化结构
		map<string, tagBuildFileInfo*>::iterator leafItr = pInfo->mapBuildFileInfo.begin();
		for(; leafItr != pInfo->mapBuildFileInfo.end(); leafItr++)
		{
			tagBuildFileInfo* leafInfo = leafItr->second;
			CEntityGroup* pLeaf = new CEntityGroup(leafInfo->strLeafComFlag, leafInfo->leafGuid);
			if(pLeaf)
			{
				AddChild(pLeaf);
				pLeaf->InitProperty();
			}
		}
	}
}
Example #2
0
void CDBPlayer::Load(long msgid, BYTE* msgBuf, long& msgBufPos, long bufSize)
{
    m_mapDirtyAttrData.clear();

    WORD attrNum = _GetWordFromByteArray(msgBuf, msgBufPos, bufSize); // 属性种类个数

    char varName[1024];
    for(int i=0; i<(int)attrNum; i++)
    {
        //--新格式
        //变量名字符串长度(long)
        //变量名字符串
        //变量类型(long)
        //变量数据长度(long)
        //变量数据
        long varNameLen = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量名字符串长度(long)
        _GetStringFromByteArray(msgBuf, msgBufPos, varName, bufSize);//变量名字符串
        m_mapDirtyAttrData.insert(string(varName));
        long bufType = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量类型(long)
        long varBufLen = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量数据长度(long)

        CEntityProperty* ep = NULL;
        CDataEntityManager::EntityPropertyMapItr itr = GetDataEntityManager().GetEntityPropertyMap().find(varName);
        if(itr != GetDataEntityManager().GetEntityPropertyMap().end())
            ep = itr->second;
        else
        {
            CDataEntityManager* pdeManager = NULL;
            std::map<string, CDataEntityManager*>::iterator itr = GetGame()->GetDBEntityManager()->GetObjAttrDef().find(string("player"));
            if(itr != GetGame()->GetDBEntityManager()->GetObjAttrDef().end())
                pdeManager = itr->second;

            if(pdeManager)
            {
                CEntityProperty* templateEP = pdeManager->GetEntityProperty(varName);
                if(templateEP)
                    ep = GetDataEntityManager().CreateEntityProperty(varName, templateEP->GetDBTableName(), templateEP->GetDataType());
                else
                    AddLogText("根据属性名[%s]查找属性指针为空!", varName);
            }
        }

        assert(ep != NULL);

        switch((DATA_OBJECT_TYPE)bufType)
        {
        case DATA_OBJECT_TIME:
        {
            // 6个long值 : 年 月 日 时 分 秒
            BYTE timeValue[6*sizeof(DWORD)];
            memset(timeValue, 0, 6*sizeof(DWORD));
            _GetBufferFromByteArray(msgBuf, msgBufPos, timeValue, 6*sizeof(DWORD), bufSize);
            ep->SetBufAttr(0, timeValue, 6*sizeof(DWORD));
        }
        break;
        case DATA_OBJECT_STRING:
        {
            char varValue[1024];
            _GetStringFromByteArray(msgBuf, msgBufPos, varValue, bufSize);//变量数据
            ep->SetStringAttr(0, string((char*)varValue));
        }
        break;
        case DATA_OBJECT_FLOAT:
        case DATA_OBJECT_LONG:
        case DATA_OBJECT_SHORT:
        case DATA_OBJECT_ULONG:
        case DATA_OBJECT_USHORT:
        case DATA_OBJECT_BOOL:
        case DATA_OBJECT_CHAR:
        case DATA_OBJECT_BYTE:
        case DATA_OBJECT_WORD:
        case DATA_OBJECT_DWORD:
        {
            long value = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量数据
            ep->SetLongAttr(0, (long)value);
        }
        break;
        case DATA_OBJECT_GUID:
        {
            CGUID tGUID;
            _GetBufferFromByteArray(msgBuf, msgBufPos, tGUID, bufSize);//变量数据
            ep->SetGuidAttr(0, tGUID);
        }
        break;
        case DATA_OBJECT_BUFFER:
        {
            BYTE* buf = new BYTE[varBufLen];
            _GetBufferFromByteArray(msgBuf, msgBufPos, buf, varBufLen, bufSize);//变量数据
            ep->SetBufAttr(0, buf, varBufLen);
            SAFE_DELETE_ARRAY(buf);
        }
        break;
        }
    }
}
Example #3
0
void CEntityGroup::GetFromByteArray(BYTE* msgBuf, long& msgBufPos, long bufSize)
{
	QueryDataRelease();
	RetQueryDataRelease();

	// 查询变量
	long lQueryAttrNum = _GetWordFromByteArray(msgBuf, msgBufPos, bufSize);
	for(int j=0; j<lQueryAttrNum; j++)
	{	
		char szQueryStrName[128];
		_GetStringFromByteArray(msgBuf, msgBufPos, szQueryStrName, bufSize);
		DATA_OBJECT_TYPE objType = (DATA_OBJECT_TYPE)_GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量类型(long)
		long lQueryBufSize = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);
		CTempEntityProperty* pEP = new CTempEntityProperty(szQueryStrName, objType);
		if(pEP)
		{
			switch(objType)
			{
			case  DATA_OBJECT_BUFFER:
				{
					if(lQueryBufSize>0)
					{
						BYTE* queryBuf = new BYTE[lQueryBufSize];
						_GetBufferFromByteArray(msgBuf, msgBufPos, queryBuf, lQueryBufSize, bufSize);
						pEP->SetBufAttr(queryBuf, lQueryBufSize);
						SAFE_DELETE_ARRAY(queryBuf);
					}
				}
				break;
			case  DATA_OBJECT_STRING:
				{
					char szValue[128];
					memset(szValue, 0, sizeof(szValue));
					_GetStringFromByteArray(msgBuf, msgBufPos, szValue, bufSize);
					pEP->SetStringAttr(string(szValue));
				}
				break;
			case DATA_OBJECT_GUID:
				{
					CGUID tGuid;
					_GetBufferFromByteArray(msgBuf, msgBufPos, tGuid, bufSize);
					pEP->SetGuidAttr(tGuid);
				}
				break;
			case DATA_OBJECT_BOOL:
			case DATA_OBJECT_CHAR:
			case DATA_OBJECT_BYTE:
			case DATA_OBJECT_SHORT:
			case DATA_OBJECT_WORD:
			case DATA_OBJECT_USHORT:
			case DATA_OBJECT_FLOAT:
			case DATA_OBJECT_LONG:
			case DATA_OBJECT_ULONG:
			case DATA_OBJECT_DWORD:
				{
					pEP->SetLongAttr(_GetLongFromByteArray(msgBuf, msgBufPos, bufSize));
				}
				break;
			}

			DB_RELATE_TYPE relateType = (DB_RELATE_TYPE)_GetByteFromByteArray(msgBuf, msgBufPos, bufSize);
			pEP->SetDbRelateType(relateType);
			m_pQueryDataMgr.push_back(pEP);
		}
	}

	// 查询返回的变量
	lQueryAttrNum = _GetWordFromByteArray(msgBuf, msgBufPos, bufSize);
	for(int j=0; j<lQueryAttrNum; j++)
	{	
		char szQueryStrName[128];
		_GetStringFromByteArray(msgBuf, msgBufPos, szQueryStrName, bufSize);
		DATA_OBJECT_TYPE objType = (DATA_OBJECT_TYPE)_GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量类型(long)
		CTempEntityProperty* pEP = new CTempEntityProperty(szQueryStrName, objType);
		if(pEP)
		{
			switch(objType)
			{
			case  DATA_OBJECT_STRING:
				{
					char szValue[128];
					memset(szValue, 0, sizeof(szValue));
					_GetStringFromByteArray(msgBuf, msgBufPos, szValue, bufSize);
					pEP->SetStringAttr(string(szValue));
				}
				break;
			case DATA_OBJECT_GUID:
				{
					CGUID tGuid;
					_GetBufferFromByteArray(msgBuf, msgBufPos, tGuid, bufSize);
					pEP->SetGuidAttr(tGuid);
				}
				break;
			case DATA_OBJECT_BOOL:
			case DATA_OBJECT_CHAR:
			case DATA_OBJECT_BYTE:
			case DATA_OBJECT_SHORT:
			case DATA_OBJECT_WORD:
			case DATA_OBJECT_USHORT:
			case DATA_OBJECT_FLOAT:
			case DATA_OBJECT_LONG:
			case DATA_OBJECT_ULONG:
			case DATA_OBJECT_DWORD:
				{
					pEP->SetLongAttr(_GetLongFromByteArray(msgBuf, msgBufPos, bufSize));
				}
				break;
			}

			DB_RELATE_TYPE relateType = (DB_RELATE_TYPE)_GetByteFromByteArray(msgBuf, msgBufPos, bufSize);
			pEP->SetDbRelateType(relateType);
			m_pRetQueryDataMgr.push_back(pEP);
		}
	}
	

	// 解析消息
	WORD attrNum = _GetWordFromByteArray(msgBuf, msgBufPos, bufSize); // 属性种类个数
	if(attrNum)
	{
		for(int i=0; i<(int)attrNum; i++)
		{
			long lAttrEnum = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量类型枚举值(long)
			long varBufLen = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量数据长度(long)

			CEntityProperty* ep = NULL;
			long bufType = GetGame()->GetEntityManager()->GetDataObjectType(GetCompositeFlag(), lAttrEnum);
			CDataEntityManager::EntityPropertyMapItr itr = GetDataEntityManager().GetEntityPropertyMap().find(lAttrEnum);
			if(itr != GetDataEntityManager().GetEntityPropertyMap().end())
				ep = itr->second;

			assert(ep != NULL);

			switch((DATA_OBJECT_TYPE)bufType)
			{
			case DATA_OBJECT_TIME:
				{
					// 6个long值 : 年 月 日 时 分 秒
					BYTE timeValue[6*sizeof(DWORD)];
					memset(timeValue, 0, 6*sizeof(DWORD));
					_GetBufferFromByteArray(msgBuf, msgBufPos, timeValue, 6*sizeof(DWORD), bufSize);
					ep->SetBufAttr(timeValue, 6*sizeof(DWORD));
				}
				break;
			case DATA_OBJECT_STRING:
				{
					char varValue[1024];
					_GetStringFromByteArray(msgBuf, msgBufPos, varValue, bufSize);//变量数据
					ep->SetStringAttr(string((char*)varValue));
				}
				break;
			case DATA_OBJECT_FLOAT:
			case DATA_OBJECT_LONG:
			case DATA_OBJECT_SHORT:
			case DATA_OBJECT_ULONG:
			case DATA_OBJECT_USHORT:
			case DATA_OBJECT_BOOL:
			case DATA_OBJECT_CHAR:
			case DATA_OBJECT_BYTE:
			case DATA_OBJECT_WORD:
			case DATA_OBJECT_DWORD:
				{
					long value = _GetLongFromByteArray(msgBuf, msgBufPos, bufSize);//变量数据
					ep->SetLongAttr((long)value);
				}
				break;
			case DATA_OBJECT_GUID:
				{
					CGUID tGUID;
					_GetBufferFromByteArray(msgBuf, msgBufPos, tGUID, bufSize);//变量数据
					ep->SetGuidAttr(tGUID);
				}
				break;
			case DATA_OBJECT_BUFFER:
				{
					BYTE* buf = new BYTE[varBufLen];
					_GetBufferFromByteArray(msgBuf, msgBufPos, buf, varBufLen, bufSize);//变量数据
					ep->SetBufAttr(buf, varBufLen);
					SAFE_DELETE_ARRAY(buf);
				}
				break;
			}
		}
	}

	//////////////////////////////////////////////////////////////////////////
	// 是否有数据标志位
	bool isLoadFlag = false;
	WORD num = _GetWordFromByteArray(msgBuf, msgBufPos, bufSize);
	if(num)
	{
		for(int j=0; j<num; j++)
		{
			BYTE entityType = _GetByteFromByteArray(msgBuf, msgBufPos, bufSize);

			char comFlag[64];
			memset(comFlag, 0, sizeof(comFlag));
			_GetStringFromByteArray(msgBuf, msgBufPos, comFlag, bufSize);
			CGUID guid;
			_GetBufferFromByteArray(msgBuf, msgBufPos, guid, bufSize);

			BYTE DbOperFlag = _GetByteFromByteArray(msgBuf, msgBufPos, bufSize);
			BYTE DBOperType = _GetByteFromByteArray(msgBuf, msgBufPos, bufSize);
			if(DBOperType == DB_OPER_LOAD || DBOperType == DB_OPER_LOAD_NOCACHE)
				isLoadFlag = true;

			if(DbOperFlag != 1) continue;
			switch(DBOperType)
			{
			case DB_OPER_DELETE_INSERT:
			case DB_OPER_ONLY_MEMSAVE:
				{
					CBaseEntity* pEntity = GetChild(guid);
					if(pEntity) 
					{
						if(pEntity->GetCompositeType() == COM_COMPOSITE)
						{
							if(!((CEntityGroup*)pEntity)->GetHasDetailLeavesFlag())// 非分层group(GoodsGroup)
							{
								ReleaseLeaf(guid);
								pEntity = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
								AddChild(pEntity);
							}
						}
					}
					else
					{
						pEntity = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
						AddChild(pEntity);
					}

					if(pEntity)
					{
						pEntity->SetCurDbOperType(DBOperType);
						pEntity->SetCurDbOperFlag(DbOperFlag);
						if(DbOperFlag == 1)
						{
							pEntity->GetFromByteArray(msgBuf, msgBufPos, bufSize);
						}
					}						
				}
				break;
			case DB_OPER_DELETE:
				{
					CBaseEntity* pEntity = GetChild(guid);
					if(!pEntity)
					{
						pEntity = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
						AddChild(pEntity);
					}
					if(pEntity)
					{
						pEntity->SetCurDbOperFlag(DbOperFlag);
						pEntity->SetCurDbOperType(DBOperType);
						if(DbOperFlag == 1)
							pEntity->GetFromByteArray(msgBuf, msgBufPos, bufSize);
					}
				}
				break;
			case DB_OPER_INSERT:
				{
					CBaseEntity* pEntity = GetChild(guid);
					if(!pEntity)
					{
						pEntity = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
						AddChild(pEntity);
					}
					if(pEntity)
					{
						pEntity->SetCurDbOperType(DBOperType);
						pEntity->SetCurDbOperFlag(DbOperFlag);
						if(DbOperFlag == 1)
							pEntity->GetFromByteArray(msgBuf, msgBufPos, bufSize);
					}						
				}
				break;
			case DB_OPER_SAVE:
				{
					CBaseEntity* pLeaf = GetChild(guid);
					if(!pLeaf)
					{
						pLeaf = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
						AddChild(pLeaf);
					}
					if(pLeaf)
					{
						pLeaf->SetCurDbOperType(DBOperType);
						pLeaf->SetCurDbOperFlag(DbOperFlag);
						if(DbOperFlag == 1)
							pLeaf->GetFromByteArray(msgBuf, msgBufPos, bufSize);
					}
				}
				break;
			case DB_OPER_LOAD:
			case DB_OPER_LOAD_NOCACHE:
				{
					CBaseEntity* pLeaf = GetChild(guid);
					if(!pLeaf)
					{
						pLeaf = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
						AddChild(pLeaf);
					}
					if(pLeaf)
					{
						pLeaf->SetCurDbOperType(DBOperType);
						pLeaf->SetCurDbOperFlag(DbOperFlag);
						if(DbOperFlag == 1)
							pLeaf->GetFromByteArray(msgBuf, msgBufPos, bufSize);
					}
				}
				break;
			default:
				{	
					CBaseEntity* pEntity = GetGame()->GetEntityManager()->NewBaseEntity(comFlag, guid);
					if(pEntity)
					{
						pEntity->SetCurDbOperType(DBOperType);
						pEntity->SetCurDbOperFlag(DbOperFlag);
						if(DbOperFlag == 1)
							pEntity->GetFromByteArray(msgBuf, msgBufPos, bufSize);
					}
					SAFE_DELETE(pEntity);
					AddLogText("GetFromByteArray(): 根节点%s 子结点%s 的操作类型%d 无效!", 
						GetCompositeFlag().c_str(), comFlag, DBOperType);
				}
				break;
			}
		}
	}	

}