I think is something wrong with the Blob Arrays
Here is my item listing function, it works perfectly.
Code:
bool MMatchServer::ResponseCharacterItemList( MUID& uidPlayer )
{
MMatchObject* pMatchObject = GetObject( uidPlayer );
if( pMatchObject && pMatchObject->m_pCharInfo )
{
if( !m_MatchDBMgr.GetCharItemInfo( pMatchObject->m_pCharInfo ) )
{
MLog( "DB Query(ResponseCharacterItemList > GetCharItemInfo) Failed" );
return false;
}
MCommand* pCmd = CreateCommand( MATCH_RESPONSECHARACTERITEMLIST, uidPlayer );
if( pCmd )
{
pCmd->AddParameter( new MCommandParameterUInt( pMatchObject->m_pCharInfo->m_nBP ) );
void* pArray = MMakeBlobArray( sizeof( MTD_ItemNode ), 12 );
for( int i = 0; i != 12; i++ )
{
MTD_ItemNode Item;
MMatchItem* pItem = pMatchObject->m_pCharInfo->m_EquipedItem.GetItem( (MMatchCharItemParts)i );
if( pItem )
{
Item.nItemID = pItem->m_pDesc->m_nID;
Item.uidItem = pItem->m_uidItem;
}else{
Item.nItemID = 0;
Item.uidItem = MUID( 0, 0 );
}
memcpy( MGetBlobArrayElement( pArray, i ), &Item, sizeof( MTD_ItemNode ) );
}
pCmd->AddParameter( new MCommandParameterBlob( pArray, MGetBlobArraySize( pArray ) ) );
MEraseBlobArray( pArray );
pArray = MMakeBlobArray( sizeof( MTD_ItemNode ), pMatchObject->m_pCharInfo->m_ItemList.size() );
map<MUID, MMatchItem*>::iterator it = pMatchObject->m_pCharInfo->m_ItemList.begin();
for( int i = 0; it != pMatchObject->m_pCharInfo->m_ItemList.end(); it++, i++ )
{
MMatchItem* pItem = (*it).second;
if( !pItem )
continue;
MTD_ItemNode Item;
Item.nItemID = pItem->m_pDesc->m_nID;
Item.uidItem = pItem->m_uidItem;
memcpy( MGetBlobArrayElement( pArray, i ), &Item, sizeof( MTD_ItemNode ) );
}
pCmd->AddParameter( new MCommandParameterBlob( pArray, MGetBlobArraySize( pArray ) ) );
MEraseBlobArray( pArray );
RouteToListener( pMatchObject, pCmd );
return true;
}
}
return false;
}
Also remember that the blob arrays are 8 bytes lenght, the first 4 bytes is the element size and the last 4 bytes the element count.
Code:
void* MMakeBlobArray( int nOneBlobSize, int nBlobCount )
{
unsigned char* pArray = new unsigned char[ nOneBlobSize * nBlobCount + 8 ];
*(int*)( pArray ) = nOneBlobSize;
*(int*)( pArray + 4 ) = nBlobCount;
return pArray;
}
void* MGetBlobArrayElement( void* pBlob, int nIndex )
{
if( nIndex < 0 || nIndex > *(int*)( (unsigned char*)pBlob + 4 ) )
return NULL;
return (unsigned char*)pBlob + nIndex * *(int*)( pBlob ) + 8;
}
int MGetBlobArraySize( void* pBlob )
{
return *(int*)(unsigned char*)pBlob * *(int*)( (unsigned char*)pBlob + 4 ) + 8;
}
int MGetBlobArrayCount( void* pBlob )
{
return *(int*)( (unsigned char*)pBlob + 4 );
}
void MEraseBlobArray( void* pBlob )
{
delete [] pBlob;
}