本文整理汇总了C++中CBuffer::Use方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::Use方法的具体用法?C++ CBuffer::Use怎么用?C++ CBuffer::Use使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::Use方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _GetGameStat
void CClientNode::_GetGameStat( const void *pData, size_t dataLength )
{//发送游戏统计数据(By Fellow,2003.7.22)
ASSERT( m_pServer && pData && dataLength );
#ifdef CONSOLE_DEBUG
cout << "_GetGameStat::Begin" << endl;
#endif
//收到的数据包,只有控制字没有数据
TProcessData *pProData = ( TProcessData * )pData;
size_t nIdentity = pProData->ulIdentity;
//需要发送的数据包
CBuffer *pBuffer = m_theAllocator.Allocate();
TProcessData *pStatData =
reinterpret_cast< TProcessData * >( const_cast< BYTE * >( pBuffer->GetBuffer() ) );
int nDataLen = sizeof(TGAME_STAT_DATA);
pStatData->nProtoId = s2c_gamestatistic;
pStatData->ulIdentity = nIdentity;
pStatData->nDataLen = nDataLen;
//取得统计数据
TGAME_STAT_DATA* myGameStatData = (TGAME_STAT_DATA*)pStatData->pDataBuffer;
GetGameStat(myGameStatData);
int nUsedLen = sizeof( TProcessData ) - 1 + nDataLen;
pBuffer->Use( nUsedLen );
//发送
m_theSend.AddData( s2c_gamestatistic_bigpackage, pBuffer->GetBuffer(), nUsedLen );
CBuffer *pPack = m_theSend.GetHeadPack( s2c_gamestatistic_bigpackage );
while ( pPack )
{
m_pServer->SendData( m_nIndentity, ( const void * )pPack->GetBuffer(), pPack->GetUsed() );
SAFE_RELEASE( pPack );
pPack = m_theSend.GetNextPack( s2c_gamestatistic_bigpackage );
}
m_theSend.DelData( s2c_gamestatistic_bigpackage );
SAFE_RELEASE( pPack );
SAFE_RELEASE( pBuffer );
#ifdef CONSOLE_DEBUG
cout << "_GetGameStat::End" << endl;
#endif
}
示例2: _GetRoleInfo
void CClientNode::_GetRoleInfo( const void *pData, size_t dataLength )
{
ASSERT( m_pServer && pData && dataLength );
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::Begin" << endl;
#endif
TProcessData *pRoleInfo = ( TProcessData * )pData;
char szRoleName[_NAME_LENGTH];
int nDataLen = pRoleInfo->nDataLen;
nDataLen = ( nDataLen > _NAME_LENGTH ) ? _NAME_LENGTH : nDataLen;
CBuffer *pBuffer = m_theAllocator.Allocate();
TProcessData *pRoleData = reinterpret_cast< TProcessData * >( const_cast< BYTE * >( pBuffer->GetBuffer() ) );
int nUsedLength = sizeof( TProcessData );
size_t nIdentity = pRoleInfo->ulIdentity;
pRoleData->nProtoId = s2c_roleserver_getroleinfo_result;
pRoleData->pDataBuffer[0] = -1;
pRoleData->nDataLen = 1;
pRoleData->ulIdentity = nIdentity;
if ( nDataLen > 0 )
{
memcpy( szRoleName, &pRoleInfo->pDataBuffer[0], nDataLen );
szRoleName[nDataLen] = '\0';
int result = -1;
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::GetRoleInfo " << szRoleName << endl;
#endif
int nRoleInfoLen = 0;
if (!IsRoleLock(szRoleName))
GetRoleInfo( &pRoleData->pDataBuffer[1], szRoleName, nRoleInfoLen );
if ( nRoleInfoLen > 0 )
{
pRoleData->pDataBuffer[0] = 1;
pRoleData->nDataLen = nRoleInfoLen + 1;
nUsedLength = sizeof( TProcessData ) + nRoleInfoLen;
}
}
pBuffer->Use( nUsedLength );
m_theSend.AddData( s2c_roleserver_getroleinfo_result, pBuffer->GetBuffer(), nUsedLength, nIdentity );
CBuffer *pPack = m_theSend.GetHeadPack( s2c_roleserver_getroleinfo_result );
while ( pPack )
{
m_pServer->SendData( m_nIndentity, ( const void * )pPack->GetBuffer(), pPack->GetUsed() );
SAFE_RELEASE( pPack );
pPack = m_theSend.GetNextPack( s2c_roleserver_getroleinfo_result );
}
m_theSend.DelData( s2c_roleserver_getroleinfo_result );
SAFE_RELEASE( pPack );
SAFE_RELEASE( pBuffer );
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::End" << endl;
#endif
}
示例3: _QueryRoleList
void CClientNode::_QueryRoleList( const void *pData, size_t dataLength )
{
char szAccountName[_NAME_LENGTH];
ASSERT( m_pServer && pData && dataLength );
#ifdef CONSOLE_DEBUG
cout << "_QueryRoleList::Begin" << endl;
#endif
TProcessData *pPlayerList = ( TProcessData * )pData;
int nRoleListCount = pPlayerList->pDataBuffer[0];
int nLen = pPlayerList->nDataLen;
unsigned long ulIdentity = pPlayerList->ulIdentity;
if ( nLen <= 1 || nLen >= _NAME_LENGTH )
{
#ifdef CONSOLE_DEBUG
cout << "_QueryRoleList::Name is invalid" << endl;
#endif
return;
}
memcpy( szAccountName, ( const char * )( &pPlayerList->pDataBuffer[1] ), nLen - 1 );
szAccountName[nLen - 1] = '\0';
/*
* Database
*/
S3DBI_RoleBaseInfo DBI[4];
const size_t s_nStructSize = sizeof( S3DBI_RoleBaseInfo );
#ifdef CONSOLE_DEBUG
cout << "_QueryRoleList::GetRoleListOfAccount " << szAccountName << endl;
#endif
int nCount = GetRoleListOfAccount( szAccountName, &DBI[0], nRoleListCount );
CBuffer *pBuffer = m_theAllocator.Allocate();
TProcessData *pListData = reinterpret_cast< TProcessData * >( const_cast< BYTE * >( pBuffer->GetBuffer() ) );
pListData->nProtoId = s2c_roleserver_getrolelist_result;
pListData->ulIdentity = ulIdentity;
int nDataLen = nCount * s_nStructSize + 1;
pListData->nDataLen = nDataLen;
pListData->pDataBuffer[0] = nCount;
memcpy( &pListData->pDataBuffer[1], &DBI[0], nDataLen );
int nUsedLen = sizeof( TProcessData ) - 1 + nDataLen;
pBuffer->Use( nUsedLen );
m_pServer->SendData( m_nIndentity, ( const void * )pListData, nUsedLen );
SAFE_RELEASE( pBuffer );
#ifdef CONSOLE_DEBUG
cout << "_QueryRoleList::end" << endl;
#endif
}