예제 #1
0
void NetServer::SetHostSettings(const char *pszCarCat,bool bCollisions)
{
	assert(m_strRaceXMLFile!="");

	void *params = GfParmReadFileLocal(m_strRaceXMLFile.c_str(),GFPARM_RMODE_STD);
	assert(params);
	const char *pName =GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, "");


	GfParmSetStr(params, RM_SECT_HEADER,RM_ATTR_CAR_CATEGORY, pszCarCat);
	GfParmWriteFileLocal(m_strRaceXMLFile.c_str(), params, pName);
}
예제 #2
0
void NetServer::GenerateDriversForXML()
{
	assert(m_strRaceXMLFile!="");

	void *params = GfParmReadFileLocal(m_strRaceXMLFile.c_str(),GFPARM_RMODE_STD);
	assert(params);
	
	const char *pName =GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, "");

    int nCars = GfParmGetEltNb(params, RM_SECT_DRIVERS);
	
	//Gather vector of all non human drivers
	std::vector<NetDriver> vecRDrivers;
	for (int i=1;i<=nCars;i++)
	{
		NetDriver driver;
		ReadDriverData(driver,i,params);
		if (strcmp(driver.module,NETWORKROBOT)	&& strcmp(driver.module,HUMANROBOT))
			vecRDrivers.push_back(driver);
	}

	//Recreate drivers section robots first
	char drvSec[256];
	GfParmListClean(params, RM_SECT_DRIVERS);
	for (int i=0;i<(int)vecRDrivers.size();i++)
	{
		int index = i+1;
		sprintf(drvSec, "%s/%d", RM_SECT_DRIVERS, index);
		GfParmSetNum(params, drvSec, RM_ATTR_IDX, (char*)NULL, (tdble)vecRDrivers[i].idx);
		GfParmSetStr(params, drvSec, RM_ATTR_MODULE, vecRDrivers[i].module);
    }

	//And then add the networkhuman drivers
	NetServerMutexData *pSData = LockServerData();
	for (int i=0;i<(int)pSData->m_vecNetworkPlayers.size();i++)
	{
		int index = i+1+vecRDrivers.size();
		sprintf(drvSec, "%s/%d", RM_SECT_DRIVERS, index);
		GfParmSetNum(params, drvSec, RM_ATTR_IDX, (char*)NULL,(tdble) pSData->m_vecNetworkPlayers[i].idx);
		GfParmSetStr(params, drvSec, RM_ATTR_MODULE, pSData->m_vecNetworkPlayers[i].module);
    }

	UnlockServerData();
	
	//Save our changes
	GfParmWriteFileLocal(m_strRaceXMLFile.c_str(), params, pName);
}
예제 #3
0
bool RobotXml::CreateRobotFile(const char*pRobotName,std::vector<NetDriver> &vecDrivers)
{
 	char buf[255];
	sprintf(buf,"drivers/%s/%s.xml",pRobotName,pRobotName);
	void *params = GfParmReadFileLocal(buf,GFPARM_RMODE_CREAT);
	//Erase existing robots
	GfParmListClean(params, "Robots");
	char path2[256];

	for (int i=0;i<(int)vecDrivers.size();i++)
	{
		sprintf(path2, "Robots/index/%d",i+1);
		GfParmSetStr(params, path2, "name",vecDrivers[i].name);
		GfParmSetStr(params, path2, "car name",vecDrivers[i].car);
		GfParmSetNum(params, path2, "race number", (char*)NULL,(tdble) vecDrivers[i].racenumber);
		GfParmSetNum(params, path2, "red", (char*)NULL, vecDrivers[i].red);
		GfParmSetNum(params, path2, "green", (char*)NULL, vecDrivers[i].green);
		GfParmSetNum(params, path2, "blue", (char*)NULL, vecDrivers[i].blue);
		GfParmSetStr(params, path2, "type",vecDrivers[i].type);
		GfParmSetStr(params, path2, "skill level",vecDrivers[i].skilllevel);
		GfParmSetStr(params, path2, "networkrace","yes");
		if (vecDrivers[i].client)
			GfParmSetStr(params, path2, "client","yes");
		else
			GfParmSetStr(params, path2, "client","no");
		

		char hostName[256];
		enet_address_get_host_ip (&vecDrivers[i].address,hostName,256);
		GfParmSetStr(params, path2, "host",hostName);
		GfParmSetNum(params, path2, "port",(char*)NULL, vecDrivers[i].address.port);
	}

	//Save our changes
	GfParmWriteFileLocal(buf, params, pRobotName);

	GfParmReleaseHandle(params);

	return true;
}