コード例 #1
0
ファイル: IPV4Address.cpp プロジェクト: Siliconsoul/ola
IPV4Address* IPV4Address::FromString(const std::string &address) {
  struct in_addr addr;
  if (!StringToAddress(address, addr))
    return NULL;

  return new IPV4Address(addr);
}
コード例 #2
0
ファイル: IPV4Address.cpp プロジェクト: Siliconsoul/ola
bool IPV4Address::FromString(const std::string &address, IPV4Address *target) {
  struct in_addr addr;
  if (!StringToAddress(address, addr))
    return false;
  *target = IPV4Address(addr);
  return true;
}
コード例 #3
0
int DjikstraTripModel::Init(const std::map<QString, QString> & mapParams)
{
	QString strValue;
	QStringList listWaypointStrings;
	QStringList::iterator iterWaypointString;
	if (RandomWalkModel::Init(mapParams))
		return 1;

	m_strFinishAddress = GetParam(mapParams, DJIKSTRATRIPMODEL_FINISH_PARAM, DJIKSTRATRIPMODEL_FINISH_PARAM_DEFAULT);
	if (!StringToAddress(m_strFinishAddress, &m_sFinishAddress))
		m_sFinishAddress.iRecord = m_sFinishAddress.iVertex = (unsigned)-1; // signal random walk

	m_strWaypoints = GetParam(mapParams, DJIKSTRATRIPMODEL_WAYPOINTS_PARAM, DJIKSTRATRIPMODEL_WAYPOINTS_PARAM_DEFAULT);

	listWaypointStrings = QStringList::split(';', m_strWaypoints, false);
	for (iterWaypointString = listWaypointStrings.begin(); iterWaypointString != listWaypointStrings.end(); ++iterWaypointString)
	{
		Address sWaypoint;
		if (StringToAddress(*iterWaypointString, &sWaypoint) && sWaypoint.iVertex != (unsigned)-1)
			m_listWaypoints.push_back(sWaypoint);
	}

	return 0;
}
コード例 #4
0
/*
 *  Initialize client
 */
void CCommunicationInterface::Client_Init_t(char* strServerName)
{
  CTSingleLock slComm(&cm_csComm, TRUE);

  ASSERT(cci_bInitialized);
  ASSERT(!cci_bClientInitialized);

  // retrieve server address from server name
  ULONG ulServerAddress = StringToAddress(strServerName);
  // if lookup failed
  if (ulServerAddress==INADDR_NONE) {
    ThrowF_t(TRANS("Host '%s' not found!\n"), strServerName);
  }

  // call client init with server address
  Client_Init_t(ulServerAddress);
};
コード例 #5
0
QString QAutoGenDialog::GetRandomAddress(const QString & strParam)
{
	QString strAddress;
	Address sAddress;
	std::map<QString, std::vector<unsigned int> >::iterator iterRecords = m_mapRandomRecords.find(strParam);
	std::map<QString, Rect>::iterator iterMapSelection = m_mapMapSelections.find(strParam);
	unsigned int i, iMaxRetries = 3, iRecord, iShapePoint;
	float fProgress;
	MapRecord * pRecord;

	if (iterRecords == m_mapRandomRecords.end())
	{
		iterRecords = m_mapRandomRecords.find(OTHERADDRESSES);
		iterMapSelection = m_mapMapSelections.find(OTHERADDRESSES);
		if (iterRecords == m_mapRandomRecords.end())
			return strAddress;
	}

	// choose a random location in this region
	if (iterRecords->second.empty())
		return strAddress;

	for (i = 0; i < iMaxRetries; i++)
	{
		iRecord = RandUInt(0, iterRecords->second.size());
		pRecord = g_pMapDB->GetRecord(iterRecords->second[iRecord]);
		if (pRecord->nShapePoints > 1)
		{
			iShapePoint = RandUInt(0, pRecord->nShapePoints - 1);
			fProgress = (float)RandDouble(0., 1.);
			if (g_pMapDB->AddressFromRecord(&sAddress, iterRecords->second[iRecord], iShapePoint, fProgress))
			{
				strAddress = AddressToString(&sAddress);
				if (StringToAddress(strAddress, &sAddress) && sAddress.iRecord != (unsigned)-1 && iterMapSelection->second.intersectRect(pRecord->rBounds))
					break;
			}
		}
	}
	return strAddress;
}
コード例 #6
0
// prepares the comm interface for use - MUST be invoked before any data can be sent/received
void CCommunicationInterface::PrepareForUse(BOOL bUseNetwork, BOOL bClient)
{

	// clear the network conditions emulation data
  _pbsSend.Clear();
  _pbsRecv.Clear();

	// if the network is already initialized, shut it down before proceeding
  if (cm_bNetworkInitialized) {
    Unprepare();
  }

  // make sure winsock is off (could be on if enumeration was triggered)
  GameAgent_EnumCancel();
  EndWinsock();

  if (bUseNetwork) {
    CPrintF(TRANSV("Initializing TCP/IP...\n"));
    if (bClient) {
      CPrintF(TRANSV("  opening as client\n"));
    } else {
      CPrintF(TRANSV("  opening as server\n"));
    }

    // make sure winsock is on
    InitWinsock();

    // no address by default
    cm_ulLocalHost = 0;
    // if there is a desired local address
    if (net_strLocalHost!="") {
      CPrintF(TRANSV("  user forced local address: %s\n"), (const char*)net_strLocalHost);
      // use that address
      cm_strName = net_strLocalHost;
      cm_ulLocalHost = StringToAddress(cm_strName);
      // if invalid
      if (cm_ulLocalHost==0 || cm_ulLocalHost==-1) {
        cm_ulLocalHost=0;
        // report it
        CPrintF(TRANSV("  requested local address is invalid\n"));
      }
    }

    // if no valid desired local address
    CPrintF(TRANSV("  getting local addresses\n"));
    // get default
    char hostname[256];
    gethostname(hostname, sizeof(hostname)-1);
    cm_strName = hostname;
    // lookup the host
    HOSTENT *phe = gethostbyname(cm_strName);
    // if succeeded
    if (phe!=NULL) {
      // get the addresses
      cm_strAddress = "";
      for(INDEX i=0; phe->h_addr_list[i]!=NULL; i++) {
        if (i>0) {
          cm_strAddress += ", ";
        }
        cm_strAddress += inet_ntoa(*(const in_addr *)phe->h_addr_list[i]);
      }
    }

    CPrintF(TRANSV("  local addresses: %s (%s)\n"), (const char *) cm_strName, (const char *) cm_strAddress);
    CPrintF(TRANSV("  port: %d\n"), net_iPort);

    // try to open master UDP socket
    try {
      OpenSocket_t(cm_ulLocalHost, bClient?0:net_iPort);
			cci_pbMasterInput.pb_ppbsStats = NULL;
			cci_pbMasterOutput.pb_ppbsStats = NULL;
      cm_ciBroadcast.SetLocal(NULL);
      CPrintF(TRANSV("  opened socket: \n"));
    } catch (char *strError) {
      CPrintF(TRANSV("  cannot open UDP socket: %s\n"), strError);
    }
  }
  
  cm_bNetworkInitialized = cci_bWinSockOpen;
};
コード例 #7
0
ファイル: RenoCommand.cpp プロジェクト: m1h4/Reno
BOOL CRenoCommandFrame::CmdServer(const CStringPtrArray& commandElements)
{
	// Maybe we are already connected
	if(m_State != RENO_NETWORK_DISCONNECTED)
	{
		if(m_State == RENO_NETWORK_CONNECTED)
			PrintFormat(TEXT("* Disconnect first\r\n")); 
		else
			PrintFormat(TEXT("* Connection in progress\r\n")); 

		return FALSE;
	}

	if(commandElements.GetCount() != 2)
	{
		PrintFormat(TEXT("* Usage: %s <address> [:port]\r\n"),commandElements[0]);
		return FALSE;
	}
	
	CString hostName = commandElements[1];

	// Get server list
	for(LONG i = 0; i < theApp.GetServerList().GetCount(); ++i)
	{
		LONG index = theApp.GetServerList()[i].Find(TEXT('|'));
		if(index != -1 && hostName == theApp.GetServerList()[i].GetBuffer() + index + 1)
			hostName = theApp.GetServerList()[i].Left(index);
	}

	// Check if port specified and add default port if not
	if(hostName.Find(TEXT(':')) == -1)
	{
		hostName += TEXT(':');
		hostName += IRC_DEFAULT_PORT;
	}

	// Check if the address is numeric (no need to resolve it then)
	sockaddr_in address;
	INT length = sizeof(address);
	if(StringToAddress(hostName,(LPSOCKADDR)&address,&length))
	{
		PrintFormat(TEXT("* Connecting to %s\r\n"),hostName);

		// Connect directly
		if(!Connect((LPSOCKADDR)&address,length))
		{
			switch(WSAGetLastError())
			{
			case WSAEWOULDBLOCK:
				//m_Board.InsertString(TEXT("* Connection in progress\r\n"));
				return TRUE;	// Skip the Close()

			default:
				PrintFormat(TEXT("* Failed to connect. Connection error %d\r\n"),WSAGetLastError());
				break;
			}

			Close();
		}
	}
	else if(!Resolve(hostName))
		PrintFormat(TEXT("* Failed to initiate resolve. Resolve queue full\r\n"));
	else
		PrintFormat(TEXT("* Resolving host %s\r\n"),hostName);

	return TRUE;
}