Ejemplo n.º 1
0
// 清除子背包对象
//void CDBPlayer::ClearSubpackObjMap(long subPos)
//{
//map<long, set<CGUID>>::iterator placeItr = p_GoodsGroup->GetDirtyGoodsMap().find((long)PEI_PACK);
//if(placeItr != p_GoodsGroup->GetDirtyGoodsMap().end())
//{
//	set<CGUID>::iterator goodsItr = placeItr->second.begin();
//	while( goodsItr != placeItr->second.end() )
//	{
//		CDBGoods* packGoods = p_GoodsGroup->FindGoods(*goodsItr);
//		if(packGoods)
//		{
//			long pos = packGoods->GetLongAttr(string("position"), 0);
//			if(pos == PEI_PACK1+subPos)
//			{
//				if(!p_GoodsGroup->DelGoods(*goodsItr, (long)PEI_PACK))
//				{
//					char szPlayerID[128];
//					char szGoodsID[128];
//					GetExID().tostring(szPlayerID);
//					(*goodsItr).tostring(szGoodsID);
//					AddLogText("CDBPlayer::ClearSubpackObjMap del goods Err!Player[%s], goods[%s], pos[%d]!", szPlayerID, szGoodsID, pos);
//				}
//				placeItr->second.erase((*goodsItr));
//				break;
//			}
//		}
//		goodsItr++;
//	}
//	if(placeItr->second.size() == 0) // 已清空
//	{
//		p_GoodsGroup->GetDirtyGoodsMap().erase(placeItr);
//	}
//}
//}
// 初始化属性配置
void CDBPlayer::InitProperty()
{
    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)
    {
        CDataEntityManager::EntityPropertyMapItr attrItr = pdeManager->GetEntityPropertyMap().begin();

        for(; attrItr != pdeManager->GetEntityPropertyMap().end(); attrItr++)
        {
            CEntityProperty* pe = m_DataEntityManager.CreateEntityProperty(attrItr->first, attrItr->second->GetDBTableName(), attrItr->second->GetDataType());
            if(pe)
            {
                if(pe->GetDataType() == DATA_OBJECT_TIME)
                {
                    long timeBuf[6] = {0};
                    timeBuf[0] = 1990;
                    timeBuf[1] = 1;
                    timeBuf[2] = 1;
                    pe->SetBufAttr(0, (void*)&timeBuf[0], sizeof(DWORD)*6);
                }
            }
        }
    }
    else
    {
        AddLogText("CDBPlayer::InitProperty() Err,未找到相关配置信息!");
    }
}
Ejemplo n.º 2
0
// 初始化属性配置
void CDBFactionMember::InitProperty()
{
	CDataEntityManager* pdeManager = NULL;
	std::map<string, CDataEntityManager*>::iterator itr = GetGame()->GetDBEntityManager()->GetObjAttrDef().find(string("faction_member"));
	if(itr != GetGame()->GetDBEntityManager()->GetObjAttrDef().end())
		pdeManager = itr->second;

	if(pdeManager)
	{
		CDataEntityManager::EntityPropertyMapItr attrItr = pdeManager->GetEntityPropertyMap().begin();

		for(; attrItr != pdeManager->GetEntityPropertyMap().end(); attrItr++)
		{
			CEntityProperty* ep = m_DataEntityManager.CreateEntityProperty(attrItr->first, attrItr->second->GetDBTableName(), attrItr->second->GetDataType());
			if(ep)
			{
				ep->SetDbFlag(attrItr->second->GetDbFlag());
				if(ep->GetDataType() == DATA_OBJECT_TIME)
				{
					long timeBuf[6] = {0};
					timeBuf[0] = 1990;
					timeBuf[1] = 1;
					timeBuf[2] = 1;
					ep->SetBufAttr(0, (void*)&timeBuf[0], sizeof(DWORD)*6);
				}
			}
		}
	}
}
Ejemplo n.º 3
0
// 检查更新属性里是否有指定表名的属性名
bool CDBFactionMember::FindTableUpdateFlag(const string& tableName)
{
	set<string>::iterator itr = m_mapDirtyAttrData.begin();
	for (; itr != m_mapDirtyAttrData.end(); itr++)
	{
		CEntityProperty* ep = GetDataEntityManager().GetEntityProperty(*itr);
		if( ep )
		{
			if(ep->GetDBTableName() == tableName)
				return true;
		}
	}
	return false;
}
Ejemplo n.º 4
0
//存Buffer
bool CRsDupRgn::SaveBufferField(CBaseDBEntity *pGoods, const char* szFiledName, _RecordsetPtr &rs)
{
	if(pGoods == NULL)	return false;
	if(szFiledName == NULL) return false;

	VARIANT varBLOB;
	SAFEARRAY* psa;

	CEntityProperty* ep = pGoods->GetDataEntityManager().GetEntityProperty(string(szFiledName));
	if(NULL == ep) return false;

	BYTE* buffer = NULL;
	long dataSize = ep->GetBufSize(0);
	if(dataSize)
	{
		buffer = new BYTE[dataSize];
		ep->GetBufAttr(0, (void*)buffer, dataSize);
		
		long lSize=(long)dataSize;
		SAFEARRAYBOUND rgsabound[1];
		rgsabound[0].lLbound=0;
		rgsabound[0].cElements=lSize;
		psa=SafeArrayCreate(VT_UI1,1,rgsabound);

		for(long i=0;i<lSize;i++)
		{
			SafeArrayPutElement(psa,&i,&buffer[i]);
		}
		varBLOB.vt=VT_ARRAY|VT_UI1;
		varBLOB.parray=psa;

		try
		{
			rs->GetFields()->GetItem(szFiledName)->AppendChunk(varBLOB);
		}
		catch(_com_error e)
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN, STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
			SAFE_DELETE_ARRAY(buffer);
			return false;
		}
		SafeArrayDestroy(psa);
	}
	SAFE_DELETE_ARRAY(buffer);
	return true;
}
Ejemplo n.º 5
0
//读Buffer
bool CRsDupRgn::LoadBufferField(CBaseDBEntity *pGoods, const char* szFiledName, _RecordsetPtr &rs)
{
	if(pGoods == NULL)	return false;

	try
	{
		if(rs->GetadoEOF())
		{
			ReleaseRs(rs);
			return false;
		}

		long lSize=0;
		FieldsPtr fldPtr = rs->GetFields();
		FieldPtr itemPtr = fldPtr->GetItem(szFiledName);
		lSize = itemPtr->ActualSize;

		if(lSize > 0)
		{
			_variant_t varBLOB;
			varBLOB = itemPtr->GetChunk(lSize);

			BYTE *pBuf=NULL;
			SafeArrayAccessData(varBLOB.parray,(void**)&pBuf);
			SafeArrayUnaccessData(varBLOB.parray);

			// 清空SKILL
			CEntityProperty* ep = pGoods->GetDataEntityManager().GetEntityProperty(string(szFiledName));
			if(ep)
				ep->SetBufAttr(0, pBuf, lSize);
		}
	}
	catch(_com_error e)
	{
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_LOADRGNOBJERR), e);
		return false;
	}
	return true;
}
Ejemplo n.º 6
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;
        }
    }
}
Ejemplo n.º 7
0
void CDBPlayer::AddEntityDataToMsg(DB_OPERATION_TYPE opType, vector<BYTE>& pBA)
{
    // 传递来的消息前面已经加入了
    // OPEntityID:    4byte, 操作实体的ID值
    // DBOP Type:     1byte, 数据库操作类型(枚举值)
    // MSG ID:        4byte, 该消息的MSGID
    // Entity Num:    2byte, 该实体个数
    WORD attrNum = m_mapDirtyAttrData.size();
    _AddToByteArray(&pBA, m_GUID); // 实体ID
    _AddToByteArray(&pBA, (WORD)attrNum); // 属性种类个数

    //--新格式
    //变量名字符串长度(long)
    //变量名字符串
    //变量类型(long)
    //变量数据长度(long)
    //变量数据
    set<string>::iterator itr = m_mapDirtyAttrData.begin();
    for(; itr != m_mapDirtyAttrData.end(); itr++)
    {
        CEntityProperty* ep = GetDataEntityManager().GetEntityProperty(*itr);
        if(ep)
        {
            _AddToByteArray(&pBA, (long)(*itr).size());//变量名字符串长度(long)
            _AddToByteArray(&pBA, (*itr).c_str());//变量名字符串
            _AddToByteArray(&pBA, (long)ep->GetDataType());//变量类型(long)
            _AddToByteArray(&pBA, (long)ep->GetBufSize(0));//变量数据长度(long)
            switch(ep->GetDataType())
            {
            case DATA_OBJECT_TIME:
            {
                // 6个long值 : 年 月 日 时 分 秒
                BYTE timeValue[6*sizeof(DWORD)];
                memset(timeValue, 0, 6*sizeof(DWORD));
                ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
                _AddToByteArray(&pBA, timeValue, 6*sizeof(DWORD));
            }
            break;
            case DATA_OBJECT_STRING:
            {
                _AddToByteArray(&pBA, ep->GetStringAttr(0));//变量数据
            }
            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:
            {
                _AddToByteArray(&pBA, (long)ep->GetLongAttr(0));//变量数据
            }
            break;
            case DATA_OBJECT_GUID:
            {
                CGUID tGUID;
                ep->GetGuidAttr(0, tGUID);
                _AddToByteArray(&pBA, tGUID);//变量数据
            }
            break;
            case DATA_OBJECT_BUFFER:
            {
                long bufSize = ep->GetBufSize(0);
                if(bufSize)
                {
                    BYTE* buf = new BYTE[bufSize];
                    ep->GetBufAttr(0, (void*)buf, bufSize);
                    _AddToByteArray(&pBA, buf, bufSize);//变量数据
                    SAFE_DELETE_ARRAY(buf);
                }
            }
            break;
            }
        }
    }
    m_mapDirtyAttrData.clear();
}
Ejemplo n.º 8
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();
			}
		}
	}
}
Ejemplo n.º 9
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;
			}
		}
	}	

}
Ejemplo n.º 10
0
//! 保存个人房屋内的物品信息
bool    CRsDupRgn::SaveDupRgnObj(const CGUID& ownerID, map<CGUID,CDBRgnGoods*>& goodsGroup, _ConnectionPtr& cn)
{

	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_CNPTRNULL));
		return false;
	}

	_RecordsetPtr rs;
	// 比物品个数多分配2048字节
	char *sql = new char[1024 * (goodsGroup.size()+2)];
	
	string iniName   = "phrgnobj";
	string tableName = "CSL_DUPRGN_GOODS";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		ownerID.tostring(szGUID);

		sprintf(sql, "DELETE FROM CSL_DUPRGN_GOODS WHERE DupRgnGUID='%s'", szGUID);
		// 先删除该个人房屋的成员
		if(!ExecuteCn(sql, cn))
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_DELRGNOBJFAIL));
			return false;
		}

		// 清空sql语句
		memset(sql, 0, 1024 * (goodsGroup.size()+2));

		// 生成语句头
		strcpy(sql, "INSERT INTO CSL_DUPRGN_GOODS(");

		CDataEntityManager* pObjAttrDef = NULL;
		std::map<string, CDataEntityManager*>::iterator itr = GetGame()->GetDBEntityManager()->GetObjAttrDef().find(iniName);
		if(itr != GetGame()->GetDBEntityManager()->GetObjAttrDef().end())
			pObjAttrDef = itr->second;

		if(!pObjAttrDef) return false;

		//! 生成语句身
		CDataEntityManager::EntityPropertyMapItr attrItr = pObjAttrDef->GetEntityPropertyMap().begin();
		for (; attrItr != pObjAttrDef->GetEntityPropertyMap().end(); attrItr++)
		{
			if(attrItr->second->GetDBTableName() == tableName)
			{
				CWrapDataObject* wdo = attrItr->second->GetDataObject(0);
				if(wdo)
				{
					// 添加属性字段名
					strcat(sql, attrItr->second->GetEPName().c_str());
					strcat(sql, ",");
				}
			}
		}

		long sqlLen = strlen(sql);
		sql[sqlLen-1] = '\0';
		strcat(sql, ") select ");

		map<CGUID,CDBRgnGoods*>::iterator goodsItr = goodsGroup.begin();
		for(; goodsItr != goodsGroup.end(); goodsItr++)
		{	
			//! 生成语句身
			attrItr = pObjAttrDef->GetEntityPropertyMap().begin();
			for (; attrItr != pObjAttrDef->GetEntityPropertyMap().end(); attrItr++)
			{
				if(attrItr->second)
				{
					if(attrItr->second->GetDBTableName() == tableName)
					{
						// 添加属性字段值
						CEntityProperty* ep = (goodsItr->second)->GetDataEntityManager().GetEntityProperty(attrItr->second->GetEPName());
						if(ep)
						{
							if(ep->GetDBTableName() == tableName)
							{
								switch(ep->GetDataType())
								{
								case DATA_OBJECT_TIME:
									{
										char szTimeValue[2048];
										DWORD timeValue[6] = {0};
										ep->GetBufAttr(0, (void*)&timeValue[0], sizeof(DWORD)*6);
										sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
											timeValue[3], timeValue[4], timeValue[5]);
										//rs->PutCollect((*epItr).c_str(), szTimeValue);
										strcat(sql, "'");
										strcat(sql, szTimeValue);
										strcat(sql, "',");
									}
									break;
								case  DATA_OBJECT_STRING:
									{
										//rs->PutCollect((*epItr).c_str(), );
										strcat(sql, "'");
										const char* pStr = ep->GetStringAttr(0);
										if(pStr)
											strcat(sql, pStr);
										else
											strcat(sql, "");
										strcat(sql, "',");
									}
									break;
								case DATA_OBJECT_BUFFER:
									{
										//SaveBufferField((*goodsItr), (*epItr).c_str(), rs);
									}
									break;
								case DATA_OBJECT_GUID:
									{
										CGUID tGUID;
										ep->GetGuidAttr(0, tGUID);
										char szGuid[128];
										tGUID.tostring(szGuid);
										//rs->PutCollect((*epItr).c_str(), szGuid);
										strcat(sql, "'");
										strcat(sql, szGuid);
										strcat(sql, "',");
									}
									break;
								case DATA_OBJECT_BOOL:
								case DATA_OBJECT_CHAR:
								case DATA_OBJECT_BYTE:
									{
										//rs->PutCollect((*epItr).c_str(), (BYTE)ep->GetLongAttr(0));
										char value[32];
										memset(value, 0, sizeof(value));
										itoa((BYTE)ep->GetLongAttr(0), value, 10);
										strcat(sql, value);
										strcat(sql, ",");
									}
									break;
								case DATA_OBJECT_SHORT:
								case DATA_OBJECT_WORD:
								case DATA_OBJECT_USHORT:
									{
										//rs->PutCollect((*epItr).c_str(), (WORD)ep->GetLongAttr(0));
										char value[32];
										memset(value, 0, sizeof(value));
										itoa((WORD)ep->GetLongAttr(0), value, 10);
										strcat(sql, value);
										strcat(sql, ",");
									}
									break;
								case DATA_OBJECT_FLOAT:
								case DATA_OBJECT_LONG:
								case DATA_OBJECT_ULONG:
								case DATA_OBJECT_DWORD:
									{
										//rs->PutCollect((*epItr).c_str(), (DWORD)ep->GetLongAttr(0));
										char value[32];
										memset(value, 0, sizeof(value));
										itoa((DWORD)ep->GetLongAttr(0), value, 10);
										strcat(sql, value);
										strcat(sql, ",");
									}
									break;
								}
							}
						}
					}
				}
			}

			sqlLen = strlen(sql);
			sql[sqlLen-1] = '\0';

			strcat(sql, " union all select ");
		}
		sqlLen = strlen(sql);
		sql[sqlLen-17] = '\0';

		TESTHR(ExecuteCn(sql, cn));
		SAFE_DELETE_ARRAY(sql);
		return true;
	}
	catch (_com_error &e)
	{
		SAFE_DELETE_ARRAY(sql);
		ReleaseRs(rs);
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_SAVERGNGOODSFAIL), e);
		return false;
	}
	SAFE_DELETE_ARRAY(sql);
	return false;
}
Ejemplo n.º 11
0
//! 保存个人房屋信息
void CRsDupRgn::SaveDupRgn(CDBDupRgn* dupRgn, _ConnectionPtr& cn)
{	
	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_FINDDUPRGNPROPERTYERR));
		return;
	}

	_RecordsetPtr rs;
	char sql[1024] = "";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		dupRgn->GetExID().tostring(szGUID);
		
		sprintf(sql, "select * from dbo.CSL_DUPRGN_PROPERTY where guid='%s'", szGUID);
		TESTHR(OpenRs(sql, rs, cn, adOpenDynamic, adLockOptimistic));
	
		bool isNewCreated = false;
		if(rs->GetadoEOF()) // 没有记录,创建一个
		{
			rs->AddNew();
			isNewCreated = true;
		}

		set<string>::iterator epItr = dupRgn->GetDirtyAttrDataMap().begin();
		for(; epItr != dupRgn->GetDirtyAttrDataMap().end(); epItr++)
		{
			CEntityProperty* ep = dupRgn->GetDataEntityManager().GetEntityProperty(*epItr);
			if(ep)
			{
				if(ep->GetDBTableName() == "CSL_DUPRGN_PROPERTY")
				{
					switch(ep->GetDataType())
					{
					case DATA_OBJECT_TIME:
						{
							char szTimeValue[2048];
							DWORD timeValue[6] = {0};
							ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
							if(szTimeValue[0] != 0 && szTimeValue[1] != 0 && szTimeValue[2] != 0
								&& szTimeValue[3] != 0 && szTimeValue[4] != 0 && szTimeValue[5] != 0)
							{
								sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
									timeValue[3], timeValue[4], timeValue[5]);
								rs->PutCollect((*epItr).c_str(), szTimeValue);
							}
						}
						break;
					case  DATA_OBJECT_STRING:
						{
							const char* pStr = ep->GetStringAttr(0);
							if(pStr)
								rs->PutCollect((*epItr).c_str(), pStr);
						}
						break;
					case DATA_OBJECT_BUFFER:
						{
							SaveBufferField((CBaseDBEntity*)dupRgn, (*epItr).c_str(), rs);
						}
						break;
					case DATA_OBJECT_GUID:
						{
							CGUID tGUID;
							ep->GetGuidAttr(0, tGUID);
							char szGUID[128];
							tGUID.tostring(szGUID);
							if( (ep->GetDbFlag() == 0) ) // 0:非主键,1:主键
								rs->PutCollect((*epItr).c_str(), szGUID);
							else if(isNewCreated) // 是主键但是是刚创建对象
								rs->PutCollect((*epItr).c_str(), szGUID);
						}
						break;
					case DATA_OBJECT_BOOL:
					case DATA_OBJECT_CHAR:
					case DATA_OBJECT_BYTE:
						{
							rs->PutCollect((*epItr).c_str(), (BYTE)ep->GetLongAttr(0));
						}
						break;
					case DATA_OBJECT_SHORT:
					case DATA_OBJECT_WORD:
					case DATA_OBJECT_USHORT:
						{
							rs->PutCollect((*epItr).c_str(), (WORD)ep->GetLongAttr(0));
						}
						break;
					case DATA_OBJECT_FLOAT:
					case DATA_OBJECT_LONG:
					case DATA_OBJECT_ULONG:
					case DATA_OBJECT_DWORD:
						{
							rs->PutCollect((*epItr).c_str(), (DWORD)ep->GetLongAttr(0));
						}
						break;
					}
				}
			}
		}
		rs->Update();
		ReleaseRs(rs);
		return;
	}
	catch (_com_error &e)
	{
		ReleaseRs(rs);
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
		return;
	}

	return;
}
Ejemplo n.º 12
0
//! 数据库里添加系统信件
void CRsMail::InsertSysMailToGroup(CDBMail* pMail, MAIL_LEVEL_OPER_FLAG levelOpFlag, long level, long sex, long* countryIDArray, long countryNum, _ConnectionPtr& cn)
{
	if(!pMail || cn == NULL || !countryIDArray) return;

	// 产生sql语句
	char sql[1024];
	_RecordsetPtr rs;
	_RecordsetPtr mailRs;
	try
	{
		// 记录收信人ID
		vector<CGUID> vecRecieverID;

		TESTHR(CreateRs(rs));
		sprintf(sql, "select * FROM baseproperty WHERE ");
		if(level != -1)
		{
			if(levelOpFlag == MAIL_LEVEL_GREATANDEQUAL)
				strcat(sql, "Levels >= ");
			else if(levelOpFlag == MAIL_LEVEL_LESSANDEQUAL)
				strcat(sql, "Levels <= ");

			char szNum[128];
			itoa(level, szNum, 10);
			strcat(sql, szNum);
		}
		else if(sex != -1)
		{
			if( (sex != -1))
				strcat(sql, ", AND ");

			strcat(sql, "Sex = ");
			char szNum[128];
			itoa(sex, szNum, 10);
			strcat(sql, szNum);
		}
		else if(countryIDArray != NULL && countryNum != 0)
		{
			if( (sex != -1) || (level != -1))
				strcat(sql, ", AND ");

			for(int i=0; i<countryNum; i++)
			{
				strcat(sql, "(Country = ");
				char szNum[128];
				itoa(countryIDArray[i], szNum, 10);
				strcat(sql, szNum);
				strcat(sql, ", OR ");
			}
			long sqlLen = strlen(sql);
			sql[sqlLen-5] = '\0';
			strcat(sql, ")");
		}

		TESTHR(OpenRs(sql, rs, cn));
		while(!rs->GetadoEOF())
		{
			CGUID tGuid((_bstr_t)rs->GetCollect("guid"));
			vecRecieverID.push_back(tGuid);
			rs->MoveNext();
		}
		ReleaseRs(rs);

		TESTHR(CreateRs(mailRs));
		sprintf(sql, "select * FROM CSL_MAIL WHERE PlayerID='{00000000-0000-0000-0000-000000000000}'");
		TESTHR(OpenRs(sql, mailRs, cn));
		for(int i=0; i<vecRecieverID.size(); i++)
		{
			rs->AddNew();
			CDataEntityManager::EntityPropertyMapItr epItr = pMail->GetDataEntityManager().GetEntityPropertyMap().begin();
			for(; epItr != pMail->GetDataEntityManager().GetEntityPropertyMap().end(); epItr++)
			{
				CEntityProperty* ep = epItr->second;
				if(ep)
				{
					if(ep->GetDBTableName() == "CSL_MAIL")
					{
						switch(ep->GetDataType())
						{
						case DATA_OBJECT_TIME:
							{
								char szTimeValue[2048];
								DWORD timeValue[6] = {0};
								ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
								if(szTimeValue[0] != 0 && szTimeValue[1] != 0 && szTimeValue[2] != 0
									&& szTimeValue[3] != 0 && szTimeValue[4] != 0 && szTimeValue[5] != 0)
								{
									sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
										timeValue[3], timeValue[4], timeValue[5]);
									rs->PutCollect(epItr->first.c_str(), szTimeValue);
								}
							}
							break;
						case  DATA_OBJECT_STRING:
							{
								rs->PutCollect(epItr->first.c_str(), ep->GetStringAttr(0));
							}
							break;
						case DATA_OBJECT_BUFFER:
							{
								SaveBufferField((CBaseDBEntity*)pMail, epItr->first.c_str(), rs);
							}
							break;
						case DATA_OBJECT_GUID:
							{
								CGUID tGUID;
								ep->GetGuidAttr(0, tGUID);
								char szGUID[128];
								tGUID.tostring(szGUID);
								rs->PutCollect(epItr->first.c_str(), szGUID);
							}
							break;
						case DATA_OBJECT_BOOL:
						case DATA_OBJECT_CHAR:
						case DATA_OBJECT_BYTE:
							{
								rs->PutCollect(epItr->first.c_str(), (BYTE)ep->GetLongAttr(0));
							}
							break;
						case DATA_OBJECT_SHORT:
						case DATA_OBJECT_WORD:
						case DATA_OBJECT_USHORT:
							{
								rs->PutCollect(epItr->first.c_str(), (WORD)ep->GetLongAttr(0));
							}
							break;
						case DATA_OBJECT_FLOAT:
						case DATA_OBJECT_LONG:
						case DATA_OBJECT_ULONG:
						case DATA_OBJECT_DWORD:
							{
								rs->PutCollect(epItr->first.c_str(), (DWORD)ep->GetLongAttr(0));
							}
							break;
						}
					}
				}
			}
		}
		if(vecRecieverID.size())
			mailRs->Update();
		ReleaseRs(mailRs);
		return;
	}
	catch (_com_error &e)
	{
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_DELRGNOBJFAIL), e);
		ReleaseRs(rs);
		ReleaseRs(mailRs);
		return;
	}
	ReleaseRs(rs);
	ReleaseRs(mailRs);
	return;
}
Ejemplo n.º 13
0
//! 保存个人房屋内的物品信息
DB_OPERATION_RESULT_TYPE    CRsMail::SaveMailGoods(const CGUID& ownerID, set<CDBMailGoods*>& goodsGroup, _ConnectionPtr& cn)
{

	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_CNPTRNULL));
		return DB_OPER_RESULT_ERROR;
	}

	_RecordsetPtr rs;
	char sql[1024] = "";
	string iniName   = "mailgoods";
	string tableName = "CSL_MAIL_GOODS";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		ownerID.tostring(szGUID);

		sprintf(sql, "DELETE FROM CSL_MAIL_GOODS WHERE MailID='%s'", szGUID);
		// 先删除该个人房屋的成员
		if(!ExecuteCn(sql, cn))
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_DELRGNOBJFAIL));
			return DB_OPER_RESULT_ERROR;
		}

		TESTHR(CreateRs(rs));
		// 先查找该个人房屋的成员
		sprintf(sql, "SELECT * FROM CSL_MAIL_GOODS WHERE MailID='%s'", szGUID);
		TESTHR(OpenRs(sql, rs, cn, adOpenForwardOnly, adLockOptimistic));		

		set<CDBMailGoods*>::iterator goodsItr = goodsGroup.begin();
		for(; goodsItr != goodsGroup.end(); goodsItr++)
		{	
			rs->AddNew();
			//! 生成语句身
			CDataEntityManager::EntityPropertyMapItr attrItr = (*goodsItr)->GetDataEntityManager().GetEntityPropertyMap().begin();
			for (; attrItr != (*goodsItr)->GetDataEntityManager().GetEntityPropertyMap().end(); attrItr++)
			{
				if(attrItr->second)
				{
					// 添加属性字段值
					CEntityProperty* ep = attrItr->second; 
					if(ep)
					{
						if(ep->GetDBTableName() == tableName)
						{
							switch(ep->GetDataType())
							{
							case DATA_OBJECT_TIME:
								{
									char szTimeValue[2048];
									DWORD timeValue[6] = {0};
									ep->GetBufAttr(0, (void*)&timeValue[0], sizeof(DWORD)*6);
									sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
										timeValue[3], timeValue[4], timeValue[5]);
									rs->PutCollect(attrItr->first.c_str(), szTimeValue);
								}
								break;
							case  DATA_OBJECT_STRING:
								{
									rs->PutCollect(attrItr->first.c_str(), ep->GetStringAttr(0));
								}
								break;
							case DATA_OBJECT_BUFFER:
								{
									SaveBufferField((*goodsItr), attrItr->first.c_str(), rs);
								}
								break;
							case DATA_OBJECT_GUID:
								{
									CGUID tGUID;
									ep->GetGuidAttr(0, tGUID);
									char szGuid[128];
									tGUID.tostring(szGuid);
									rs->PutCollect(attrItr->first.c_str(), szGuid);
								}
								break;
							case DATA_OBJECT_BOOL:
							case DATA_OBJECT_CHAR:
							case DATA_OBJECT_BYTE:
								{
									rs->PutCollect(attrItr->first.c_str(), (BYTE)ep->GetLongAttr(0));
								}
								break;
							case DATA_OBJECT_SHORT:
							case DATA_OBJECT_WORD:
							case DATA_OBJECT_USHORT:
								{
									rs->PutCollect(attrItr->first.c_str(), (WORD)ep->GetLongAttr(0));
								}
								break;
							case DATA_OBJECT_FLOAT:
							case DATA_OBJECT_LONG:
							case DATA_OBJECT_ULONG:
							case DATA_OBJECT_DWORD:
								{
									rs->PutCollect(attrItr->first.c_str(), (DWORD)ep->GetLongAttr(0));
								}
								break;
							}
						}
					}
					
				}
			}
		}
		
		if(goodsGroup.size())
			rs->Update();
		return DB_OPER_RESULT_OK;
	}
	catch (_com_error &e)
	{
		ReleaseRs(rs);
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_SAVERGNGOODSFAIL), e);
		return DB_OPER_RESULT_ERROR;
	}

	return DB_OPER_RESULT_ERROR;
}
Ejemplo n.º 14
0
//! 保存个人房屋信息
void CRsMail::SaveMail(CDBMail* mail, _ConnectionPtr& cn)
{	
	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_FINDDUPRGNPROPERTYERR));
		return;
	}

	if(!mail) return;

	_RecordsetPtr rs;
	char sql[500] = "";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		mail->GetExID().tostring(szGUID);
		
		TESTHR(OpenRs("CSL_MAIL", rs, cn, adOpenForwardOnly, adLockOptimistic));
	
		if(!rs->GetadoEOF()) // 没有记录,创建一个
		{
			ReleaseRs(rs);
			AddLogText("Create mail[%s] Err,RS is NULL!", szGUID);
		}

		bool isNewCreated = false;
		BYTE phNum = rs->GetRecordCount();
		if(phNum == 0xff) // 没有记录,创建一个
		{
			rs->AddNew();
			isNewCreated = true;
		}

		set<string>::iterator epItr = mail->GetDirtyAttrDataMap().begin();
		for(; epItr != mail->GetDirtyAttrDataMap().end(); epItr++)
		{
			CEntityProperty* ep = mail->GetDataEntityManager().GetEntityProperty(*epItr);
			if(ep)
			{
				if(ep->GetDBTableName() == "CSL_MAIL")
				{
					switch(ep->GetDataType())
					{
					case DATA_OBJECT_TIME:
						{
							char szTimeValue[2048];
							DWORD timeValue[6] = {0};
							ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
							if(szTimeValue[0] != 0 && szTimeValue[1] != 0 && szTimeValue[2] != 0
								&& szTimeValue[3] != 0 && szTimeValue[4] != 0 && szTimeValue[5] != 0)
							{
								sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
									timeValue[3], timeValue[4], timeValue[5]);
								rs->PutCollect((*epItr).c_str(), szTimeValue);
							}
						}
						break;
					case  DATA_OBJECT_STRING:
						{
							rs->PutCollect((*epItr).c_str(), ep->GetStringAttr(0));
						}
						break;
					case DATA_OBJECT_BUFFER:
						{
							SaveBufferField((CBaseDBEntity*)mail, (*epItr).c_str(), rs);
						}
						break;
					case DATA_OBJECT_GUID:
						{
							CGUID tGUID;
							ep->GetGuidAttr(0, tGUID);
							char szGUID[128];
							tGUID.tostring(szGUID);
							if( (ep->GetDbFlag() == 0) ) // 0:非主键,1:主键
								rs->PutCollect((*epItr).c_str(), szGUID);
							else if(isNewCreated) // 是主键但是是刚创建对象
								rs->PutCollect((*epItr).c_str(), szGUID);
						}
						break;
					case DATA_OBJECT_BOOL:
					case DATA_OBJECT_CHAR:
					case DATA_OBJECT_BYTE:
						{
							rs->PutCollect((*epItr).c_str(), (BYTE)ep->GetLongAttr(0));
						}
						break;
					case DATA_OBJECT_SHORT:
					case DATA_OBJECT_WORD:
					case DATA_OBJECT_USHORT:
						{
							rs->PutCollect((*epItr).c_str(), (WORD)ep->GetLongAttr(0));
						}
						break;
					case DATA_OBJECT_FLOAT:
					case DATA_OBJECT_LONG:
					case DATA_OBJECT_ULONG:
					case DATA_OBJECT_DWORD:
						{
							rs->PutCollect((*epItr).c_str(), (DWORD)ep->GetLongAttr(0));
						}
						break;
					}
				}
			}
		}
		rs->Update();
		ReleaseRs(rs);
		return;
	}
	catch (_com_error &e)
	{
		ReleaseRs(rs);
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
		return;
	}

	return;
}
Ejemplo n.º 15
0
DB_OPERATION_RESULT_TYPE CRsMail::SavePlayerMails(CDBMailGroup* mailGroup, _ConnectionPtr& cn)
{
	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_FINDDUPRGNPROPERTYERR));
		return DB_OPER_RESULT_ERROR;
	}
	if(!mailGroup) return DB_OPER_RESULT_OK;

	_RecordsetPtr rs;
	char sql[1024] = "";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		mailGroup->GetOwnerGUID().tostring(szGUID);
		sprintf(sql, "SELECT * FROM CSL_MAIL WHERE PlayerID='%s'", szGUID);
		TESTHR(OpenRs(sql, rs, cn, adOpenForwardOnly, adLockOptimistic));

		set<CDBMail*>::iterator itr = mailGroup->GetMailGroupSet().begin();
		for(; itr != mailGroup->GetMailGroupSet().end(); itr++)
		{
			CDBMail* mail = *itr;
			rs->AddNew();
			set<string>::iterator epItr = mail->GetDirtyAttrDataMap().begin();
			for(; epItr != mail->GetDirtyAttrDataMap().end(); epItr++)
			{
				CEntityProperty* ep = mail->GetDataEntityManager().GetEntityProperty(*epItr);
				if(ep)
				{
					if(ep->GetDBTableName() == "CSL_MAIL")
					{
						switch(ep->GetDataType())
						{
						case DATA_OBJECT_TIME:
							{
								char szTimeValue[2048];
								DWORD timeValue[6] = {0};
								ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
								if(szTimeValue[0] != 0 && szTimeValue[1] != 0 && szTimeValue[2] != 0
									&& szTimeValue[3] != 0 && szTimeValue[4] != 0 && szTimeValue[5] != 0)
								{
									sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
										timeValue[3], timeValue[4], timeValue[5]);
									rs->PutCollect((*epItr).c_str(), szTimeValue);
								}
							}
							break;
						case  DATA_OBJECT_STRING:
							{
								rs->PutCollect((*epItr).c_str(), ep->GetStringAttr(0));
							}
							break;
						case DATA_OBJECT_BUFFER:
							{
								SaveBufferField((CBaseDBEntity*)mail, (*epItr).c_str(), rs);
							}
							break;
						case DATA_OBJECT_GUID:
							{
								CGUID tGUID;
								ep->GetGuidAttr(0, tGUID);
								char szGUID[128];
								tGUID.tostring(szGUID);
								rs->PutCollect((*epItr).c_str(), szGUID);
							}
							break;
						case DATA_OBJECT_BOOL:
						case DATA_OBJECT_CHAR:
						case DATA_OBJECT_BYTE:
							{
								rs->PutCollect((*epItr).c_str(), (BYTE)ep->GetLongAttr(0));
							}
							break;
						case DATA_OBJECT_SHORT:
						case DATA_OBJECT_WORD:
						case DATA_OBJECT_USHORT:
							{
								rs->PutCollect((*epItr).c_str(), (WORD)ep->GetLongAttr(0));
							}
							break;
						case DATA_OBJECT_FLOAT:
						case DATA_OBJECT_LONG:
						case DATA_OBJECT_ULONG:
						case DATA_OBJECT_DWORD:
							{
								rs->PutCollect((*epItr).c_str(), (DWORD)ep->GetLongAttr(0));
							}
							break;
						}
					}
				}
			}
			SaveMailGoods(mail->GetExID(), mail->GetGoodsGroupPtr()->GetGoodsGroupSet(), cn);
		}

		rs->Update();
		ReleaseRs(rs);
		return DB_OPER_RESULT_OK;
	}
	catch (_com_error &e)
	{
		ReleaseRs(rs);
		PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
		return DB_OPER_RESULT_ERROR;
	}

	return DB_OPER_RESULT_ERROR;
}