Пример #1
0
const char *CGPGroup::FindPairValue(const char *key, const char *defaultVal)
{
	CGPValue		*pair = FindPair(key);

	if (pair)
	{
		return pair->GetTopValue();
	}

	return defaultVal;
}
Пример #2
0
Status GetFloatValue(const char* jsonString, const char* name, float* value)
{
	struct jsonparse_state state;
	Status status = FindPair(jsonString, name, &state);
	if (status == OK)
	{
		return AsFloat(&state, value);
	}
	else
	{
		return status;
	}
}
Пример #3
0
Status GetBoolValue(const char* jsonString, const char* name, bool* value)
{
	struct jsonparse_state state;
	Status status = FindPair(jsonString, name, &state);
	if (status == OK)
	{
		return AsBool(&state, value);
	}
	else
	{
		return status;
	}
}
Пример #4
0
// Sup dawg, I herd u like instances in yo instances...
static void FixupInstance( void *pContext, CSimpleMapFile *pInstanceMapFile, MapEntityKeyValuePair_t *pFuncInstanceKeyValuePairs, int nNumKeyValuePairs )
{
	CASW_Map_Builder *pMapBuilder = ( CASW_Map_Builder * )pContext;
	CMapLayout *pMapLayout = pMapBuilder->GetCurrentlyBuildingMapLayout();

	int nPlacedRoomIndex = 0;
	MapEntityKeyValuePair_t *pPair = FindPair( "PlacedRoomIndex", pFuncInstanceKeyValuePairs, nNumKeyValuePairs );
	if ( pPair != NULL )
	{
		nPlacedRoomIndex = atoi( pPair->m_pValue );
	}
	else
	{
		// Only fix up placed room instances
		return;
	}

	CUtlVector< Vector > infoNodeLocations;

	// Populate the info node list only once
	// Technically we don't need to do this if we don't acutally have instances to spawn in this instance
	int nIndex = 0;
	while ( ( nIndex = pInstanceMapFile->FindEntity( "info_node", NULL, NULL, nIndex ) ) != -1 )
	{
		const MapEntity_t *pEntity = &pInstanceMapFile->GetEntities()[nIndex];
		infoNodeLocations.AddToTail( pEntity->m_vOrigin );
		++ nIndex;
	}
	
	if ( infoNodeLocations.Count() == 0 )
	{
		// No places to spawn instances in this instance
		return;
	}

	for ( int i = 0; i < pMapLayout->m_InstanceSpawns.Count(); ++ i )
	{
		CInstanceSpawn *pInstanceSpawn = &pMapLayout->m_InstanceSpawns[i];
		if ( pInstanceSpawn->GetPlacedRoomIndex() == nPlacedRoomIndex )
		{
			if ( pInstanceSpawn->GetInstanceSpawningMethod() == ISM_ADD_AT_RANDOM_NODE )
			{
				AddFuncInstance( pInstanceMapFile, pInstanceSpawn, infoNodeLocations[pInstanceSpawn->GetRandomSeed() % infoNodeLocations.Count()] );
			}
		}
	}
}
Пример #5
0
bool Contains(const char* jsonString, const char* name, const char* value)
{
	struct jsonparse_state state;
	Status status = FindPair(jsonString, name, &state);
	if ((status == OK) /*&& (state.vtype == JSON_TYPE_ARRAY)*/)
	{
		int valueLength = strlen(value);
		int next;
		do {
			next = jsonparse_next(&state);
			if ((valueLength == state.vlen) && (strncmp(jsonString + state.vstart, value, valueLength) == 0))
			{
				return TRUE;
			}
		} while (next != 0);
	}
	return FALSE;
}
Пример #6
0
// sorting a max edge downwards can only ever *remove* overlaps
void AxisSweep3::SortMaxDown(int axis, unsigned short edge, bool updateOverlaps)
{
	Edge* pEdge = m_pEdges[axis] + edge;
	Edge* pPrev = pEdge - 1;
	Handle* pHandleEdge = GetHandle(pEdge->m_handle);

	while (pEdge->m_pos < pPrev->m_pos)
	{
		Handle* pHandlePrev = GetHandle(pPrev->m_handle);

		if (!pPrev->IsMax())
		{
			// if previous edge was a minimum remove any overlap between the two handles
			if (updateOverlaps)
			{
				Handle* handle0 = GetHandle(pEdge->m_handle);
				Handle* handle1 = GetHandle(pPrev->m_handle);
				BroadphasePair* pair = FindPair(handle0,handle1);
				//assert(pair);

				if (pair)
				{
					RemoveOverlappingPair(*pair);
				}
			}

			// update edge reference in other handle
			pHandlePrev->m_minEdges[axis]++;;
		}
		else
			pHandlePrev->m_maxEdges[axis]++;

		pHandleEdge->m_maxEdges[axis]--;

		// swap the edges
		Edge swap = *pEdge;
		*pEdge = *pPrev;
		*pPrev = swap;

		// decrement
		pEdge--;
		pPrev--;
	}
}
Пример #7
0
// sorting a min edge upwards can only ever *remove* overlaps
void AxisSweep3::SortMinUp(int axis, unsigned short edge, bool updateOverlaps)
{
	Edge* pEdge = m_pEdges[axis] + edge;
	Edge* pNext = pEdge + 1;
	Handle* pHandleEdge = GetHandle(pEdge->m_handle);

	while (pEdge->m_pos > pNext->m_pos)
	{
		Handle* pHandleNext = GetHandle(pNext->m_handle);

		if (pNext->IsMax())
		{
			// if next edge is maximum remove any overlap between the two handles
			if (updateOverlaps)
			{
				Handle* handle0 = GetHandle(pEdge->m_handle);
				Handle* handle1 = GetHandle(pNext->m_handle);
				BroadphasePair* pair = FindPair(handle0,handle1);
				//assert(pair);
				if (pair)
				{
					RemoveOverlappingPair(*pair);
				}
			}

			// update edge reference in other handle
			pHandleNext->m_maxEdges[axis]--;
		}
		else
			pHandleNext->m_minEdges[axis]--;

		pHandleEdge->m_minEdges[axis]++;

		// swap the edges
		Edge swap = *pEdge;
		*pEdge = *pNext;
		*pNext = swap;

		// increment
		pEdge++;
		pNext++;
	}
}
Пример #8
0
void	SimpleBroadphase::RefreshOverlappingPairs()
{
	//first check for new overlapping pairs
	int i,j;

	for (i=0;i<m_numProxies;i++)
	{
		BroadphaseProxy* proxy0 = m_pProxies[i];
		for (j=i+1;j<m_numProxies;j++)
		{
			BroadphaseProxy* proxy1 = m_pProxies[j];
			SimpleBroadphaseProxy* p0 = GetSimpleProxyFromProxy(proxy0);
			SimpleBroadphaseProxy* p1 = GetSimpleProxyFromProxy(proxy1);

			if (AabbOverlap(p0,p1))
			{
				if ( !FindPair(proxy0,proxy1))
				{
					AddOverlappingPair(proxy0,proxy1);
				}
			}

		}
	}

	//then remove non-overlapping ones
	for (i=0;i<GetNumOverlappingPairs();i++)
	{
		BroadphasePair& pair = GetOverlappingPair(i);

		SimpleBroadphaseProxy* proxy0 = GetSimpleProxyFromProxy(pair.m_pProxy0);
		SimpleBroadphaseProxy* proxy1 = GetSimpleProxyFromProxy(pair.m_pProxy1);
		if (!AabbOverlap(proxy0,proxy1))
		{
            RemoveOverlappingPair(pair);
		}
	}

	

}
Пример #9
0
bool Downloader::FacebookLogin(const std::string& email, const std::string& pwd)
{
  if (fb_logged)
    return true;
  std::string html, fields;

  fb_logged = false;
  if (!GetUrl("http://m.facebook.com/login.php?http&refsrc=http%3A%2F%2Fm.facebook.com%2F&no_next_msg&refid=8", &html)) {
    goto end;
  }
  MSG_DEBUG("downloader", "Login connect success!");
  
  // Find m_ts value
  if (!FindNameValue(m_ts, "m_ts", html)) {
    error = "Can't find m_ts";
    goto end;
  }
  MSG_DEBUG("downloader", "m_ts=%s", m_ts.c_str());

  // Find post_form_id value
  if (!FindNameValue(post_form_id, "post_form_id", html)) {
    error = "Can't find post_form_id";
    goto end;
  } 
   MSG_DEBUG("downloader", "post_form_id=%s", post_form_id.c_str());
  
  // Find form
  if (!FindPair(form, "action", "id=\"login_form\"", html)) {
    error = "Can't find form";
    goto end;
  } 
  MSG_DEBUG("downloader", "form=%s", form.c_str());

  html.clear();

  form = "http://m.facebook.com" + form;
  fields = "lsd=&post_form_id=" + post_form_id +
           "&version=1&ajax=0&pxr=0&gps=0&email=" + UrlEncode(email) +
           "&pass="******"&m_ts=" + m_ts + "&login=Login";
  MSG_DEBUG("downloader", "Fields: %s\n", fields.c_str());
  if (!Post(form.c_str(), &html, fields.c_str())) {
    goto end;
  }
  if (html.find("abb acr aps") != std::string::npos) {
    error = _("Login error, probably invalid email or password");
    goto end;
  }
  MSG_DEBUG("downloader", "Login success!\n");

  // Find form
  if (!FindPair(form, "action", "id=\"composer_form\"", html)) {
    error = "Can't find form";
    goto end;
  } 
  MSG_DEBUG("downloader", "form=%s", form.c_str());
  
  // Find fb_dtsg
  if (!FindNameValue(fb_dtsg, "fb_dtsg", html)) {
    error = "Can't find fb_dtsg";
    goto end;
  } 
  MSG_DEBUG("downloader", "fb_dtsg=%s", fb_dtsg.c_str());

  // Find post_form_id value
  if (!FindNameValue(post_form_id, "post_form_id", html)) {
    error = "Can't find post_form_id";
    goto end;
  } 
  MSG_DEBUG("downloader", "post_form_id=%s", post_form_id.c_str());
  
  form = "http://m.facebook.com" + form;
  html.clear();

  fb_logged = true;

end:
  if (!fb_logged && IsLOGGING("download")) {
    FILE *f = fopen("out.htm", "wt");
    fwrite(html.c_str(), html.size(), 1, f);
    fclose(f);
    MSG_DEBUG("downloader", "Login failed: %s\n", error.c_str());
  }

  return fb_logged;
}
Пример #10
0
bool Downloader::FindNameValue(std::string& value, const std::string& name, const std::string& html)
{
  return FindPair(value, "value", "name=\"" + name + "\"", html);
}