// cLstServerInfo.cpp: implementation of the cLstServerInfo class.
//
//////////////////////////////////////////////////////////////////////

#include <vector> 
#include <string> 

using namespace std;

#include "typedef.h"
#include "cServerInfo.h"
#include "cLstServerInfo.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

cLstServerInfo::cLstServerInfo()
{

}

cLstServerInfo::~cLstServerInfo()
{
	m_lstServers.clear();
}

void cLstServerInfo::AddServerInfo(cServerInfo &serverInfo)
{
	int i,sz;
	int dj;
	
	sz = m_lstServers.size();

	dj=0;
	for(i=0;i<sz;i++)
	{
		if( m_lstServers[i].ServerID == serverInfo.ServerID)
			dj=1;
	}

	if(dj == 0)
		m_lstServers.push_back(serverInfo);
	else
	{

	}
}

void cLstServerInfo::UpdateStatusOfServer(Word32 serverId,Word8 serverState,Word32 rank)
{
	int i,sz;
	int dj;
	
	sz = m_lstServers.size();

	dj=0;
	for(i=0;i<sz;i++)
	{
		if( m_lstServers[i].ServerID == serverId)
		{
			m_lstServers[i].ConnectionState = serverState;
		}
	}
}

void cLstServerInfo::RestartGetNextConnectedServer()
{
	m_Pos = 0;
}

// 0 : Not Connected  
// 1 : Connecting  
// 2 : Connected Initiating  
// 3 : Connected Downloading  
// 4 : Connected  
// 5 : Connected and Queued  
// 6 : New Host  
// 7 : Removed Host (this host should be removed)  
// 8 : Black Listed  
// 9 : Not Connected and was Queued  
 

cServerInfo *cLstServerInfo::GetNextConnectedServer()
{
	cServerInfo *ptr = NULL;
	Word8 trv=0;
	Word8 cnx;
	int sz;
	sz = m_lstServers.size();

	while(trv == 0 && m_Pos < sz)
	{
		cnx = m_lstServers[m_Pos].ConnectionState;

		if( cnx >= 2 && cnx <= 5)
		{
			trv = 1;
			ptr = &m_lstServers[m_Pos];
		}
		
		m_Pos ++;
	}

	return(ptr);
}




