/**
*
* \file Asura_Chunk_MPComms_BannedList.cpp
*
* Created by Richard May - 03/11/2003 14:19:47
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
* \brief
*
**/



/************/
/* Includes.*/
/************/

// main asura header
#include "Core/Asura.h"

#ifdef ASURA_SUPPORT_MULTIPLAYER_COMMS

// local header
#include "ChunkSystem/Asura_Chunk_MPComms_BannedWordList.h"

// asura
#include "Core/Asura_String.h"
#include "ChunkSystem/Asura_SaveBlock.h"
#include "FileAccess/Asura_FileAccess.h"
#include "Multiplayer/Asura_Multiplayer_Comms_System.h"

/**************/
/* Functions. */
/**************/

/*************************************************************
 *
 * Name          : Asura_Chunk_MPComms_BannedList::Process
 *
 * Author        : Richard May
 *
 * Description   : Process for the list of banned words
 *
 *************************************************************/
bool Asura_Chunk_MPComms_BannedList::Process( Asura_Handle iFileHandle ) const
{
	for( u_int u=0; u<m_uEntries; ++u )
	{
		const char* szString = Asura_FileAccess::ReadString( iFileHandle );
		if(!szString) continue; // null string, do nothing
	
		// add to list
		int iIndex = 0;		
		Asura_Multiplayer_Comms_System::s_xProfanityList.FindNodeIndexByName( szString, true, iIndex );
	}

	return true;
}
/* end of function Process */


/*************************************************************
 *
 * Name          : Asura_Chunk_MPComms_BannedList::Create
 *
 * Author        : Richard May
 *
 * Description   : Creates the banned list chunk
 *
 *************************************************************/
void Asura_Chunk_MPComms_BannedList::Create ( Asura_SaveBlock* pxSaveBlock, Asura_String* axStringList, u_int uEntries )
{
	if(!pxSaveBlock) return;
	
	// calculate the required size	
	int iSizeInInts = 0; // file includes number of entries	
	
	u_int u=0;
	for( u=0; u<uEntries; ++u )
	{		
		iSizeInInts += axStringList[u].GetSizeInInts();
	}
	
	// find the total size of the chunk (including all the data) 
	int iChunkSize = sizeof(Asura_Chunk_MPComms_BannedList) + (iSizeInInts*4); // sizeInInts is multiplied by 4 to get size in bytes
	Asura_Chunk_MPComms_BannedList* pxChunk = (Asura_Chunk_MPComms_BannedList*)pxSaveBlock->GetAccessPointer(iChunkSize);
	if(!pxChunk) return;
	
	// set up the chunk
	pxChunk->ID = ASURA_CHUNK_MPCOMMS_BANNEDLIST;
	pxChunk->Size = iChunkSize;
	pxChunk->Version = 1;
	pxChunk->Flags = 0;

	pxChunk->m_uEntries = uEntries;
	
	int* piDest = (int*)(pxChunk+1);	
	// copy in the anim table data
	for( u=0; u<uEntries; ++u )
	{
		piDest = axStringList[u].IntCopy(piDest);
	}
}
/* end of function Create */

#endif // ASURA_SUPPORT_MULTIPLAYER_COMMS

/****************/
/* End of file. */
/****************/
