Exemplo n.º 1
0
void CPlayerLevels::ListAsync( const std::string& mode, 
	int page, int perPage,
	bool includeData, bool includeThumbs,
	const CustomData& customFilter )
{
	std::string modeSafe = mode.empty() ? "popular" : (mode == "newest" || mode == "popular" ? mode : "popular");
	char dataSafe = includeData ? 'y': 'n';
	char thumSafe = includeThumbs ? 'y': 'n';



	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kPlayerLevelListUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelListUrl2 +
		IdString + kPlayerLevelListUrl3 + modeSafe;
	sprintf_s(IdString,49,"%d", page);
	url += kPlayerLevelListUrl4 + page;
	sprintf_s(IdString,49,"%d", perPage);
	url += kPlayerLevelListUrl5; url += IdString;
	url += kPlayerLevelListUrl6;
	url += dataSafe;
	url += kPlayerLevelListUrl7;
	url += thumSafe;
	sprintf_s(IdString,49,"%d", customFilter.size());
	url += kPlayerLevelListUrl10;
	url += IdString;

	CPostPtr postData(new CPost);

	if(!customFilter.empty())
	{
		int fieldNumber = 0;
		CustomData::const_iterator  it = customFilter.begin();
		for(; it != customFilter.end(); it++)
		{
			char buff[10];
			sprintf_s(buff,9,"%d", fieldNumber);
			std::string ckey("ckey");
			std::string cdata("cdata");
			ckey += buff;
			cdata += buff;

			postData->AddText(ckey.c_str(), it->first.c_str());
			postData->AddText(cdata.c_str(), it->second.c_str());
		}
	}
	gConnectionInterface->PerformAsyncRequest(url.c_str(), 
		fastdelegate::MakeDelegate(this, &CPlayerLevels::ListAsyncComplete), postData);
	
}
Exemplo n.º 2
0
SLevelListPtr CPlayerLevels::SaveLevel( CLevel& level )
{
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kPlayerLevelSaveUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelSaveUrl2 +
		IdString + kPlayerLevelSaveUrl3 + gPlaytomic->GetSourceUrl();
	CPost postData;

	postData.AddText("data", level.GetData().c_str());
	postData.AddText("playerid", level.GetPlayerId().c_str());
	postData.AddText("playername", level.GetPlayerName().c_str());
	postData.AddText("playersource", level.GetPlayerSource().c_str());
	postData.AddText("name",level.GetName().c_str());
	postData.AddText("nothumb", "y");

	sprintf_s(IdString, 49, "%d", level.GetCustomData().size());
	postData.AddText("customfields", IdString);

	const CustomData& customData = level.GetCustomData();
	CustomData::const_iterator it = customData.begin();
	int fieldNumber = 0;
	for (; it != customData.end(); it++)
	{
		char buff[10];
		sprintf_s(buff,9,"%d", fieldNumber);
		std::string ckey("ckey");
		std::string cdata("cdata");
		ckey += buff;
		cdata += buff;

		postData.AddText(ckey.c_str(), it->first.c_str());
		postData.AddText(cdata.c_str(), it->second.c_str());
	}

	CPlaytomicResponsePtr response = gConnectionInterface->PerformSyncRequest(url.c_str(), &postData);
	SLevelListPtr returnList(new SLevelList);
	returnList->sErrorCode = response->ResponseError();
	returnList->sSucceded = response->ResponseSucceded();
	if(!response->ResponseSucceded())
	{
		return returnList;
	}

	FData id;
	id = response->ResponseData().get("LevelId", id);
	std::list<CLevel> levelList;
	AddLevel(response->ResponseData(), id.asString(), returnList->sLevelList);

	return returnList;
}
Exemplo n.º 3
0
void CLeaderboard::ListAsync( const std::string& tableName, bool highest,
	const std::string& mode, int page,
	int perPage,const  CustomData& customFilter )
{
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrlList +
		IdString + kLeaderboardUrl3;

	CPostPtr postData(new CPost);
	postData->AddText("url", gPlaytomic->GetSourceUrl().c_str());
	postData->AddText("table", tableName.c_str());
	postData->AddText("highest", highest ? "y": "n");
	postData->AddText("mode", mode.c_str());
	char buff[300];
	sprintf_s(buff,299,"%d", page);
	postData->AddText("page", buff);
	sprintf_s(buff, 299,"%d", perPage);
	postData->AddText("perpage", buff);
	sprintf_s(buff, 299,"%d", customFilter.size());
	postData->AddText("numfilters", buff);

	if(customFilter.size() > 0)
	{
		int fieldNumber = 0;
		CustomData::const_iterator it = customFilter.begin();
		for(;it != customFilter.end(); it++)
		{
			sprintf_s(buff,299,"%d", fieldNumber);
			std::string ckey("ckey");
			ckey += buff;
			std::string cdata("cdata");
			cdata += buff;
			std::string value = it->second;
			fieldNumber++;

			postData->AddText(ckey.c_str(), it->first.c_str() );
			postData->AddText(cdata.c_str(), it->second.c_str());
		}		
	}


	gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CLeaderboard::ListComple),postData);
}
Exemplo n.º 4
0
CPlaytomicResponsePtr CLeaderboard::Save( const std::string& tableName, const CScore& score, bool highest, bool allowDuplicates )
{
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrl2 +
		IdString + kLeaderboardUrl3;

	CPost postData;
	postData.AddText("url", gPlaytomic->GetSourceUrl().c_str());
	postData.AddText("table", tableName.c_str());
	postData.AddText("highest", highest ? "y": "n");
	postData.AddText("name", score.GetName().c_str());
	char buff[300];
	sprintf_s(buff,299,"%d", score.GetPoints());
	postData.AddText("points", buff);
	
	sprintf_s(buff,299,"%s%d",gPlaytomic->GetSourceUrl().c_str(), score.GetPoints());
	postData.AddText("auth", MD5(buff).hexdigest().c_str());

	CustomData customData = score.GetCustomData();
	sprintf_s(buff,299,"%d", customData.size());
	postData.AddText("customfields", buff);

	int fieldNumber = 0;
	CustomData::iterator it = customData.begin();
	for(;it != customData.end(); it++)
	{
		sprintf_s(buff,299,"%d", fieldNumber);
		std::string ckey("ckey");
		ckey += buff;
		std::string cdata("cdata");
		cdata += buff;
		std::string value = it->second;
		fieldNumber++;

		postData.AddText(ckey.c_str(), it->first.c_str() );
		postData.AddText(cdata.c_str(), it->second.c_str());
	}

	return gConnectionInterface->PerformSyncRequest(url.c_str(), &postData);
}
Exemplo n.º 5
0
void CPlayerLevels::SaveLevelAsync( CLevel& level )
{
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kPlayerLevelSaveUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelSaveUrl2 +
		IdString + kPlayerLevelSaveUrl3 + gPlaytomic->GetSourceUrl();
	CPostPtr postData(new CPost);

	postData->AddText("data", level.GetData().c_str());
	postData->AddText("playerid", level.GetPlayerId().c_str());
	postData->AddText("playername", level.GetPlayerName().c_str());
	postData->AddText("playersource", level.GetPlayerSource().c_str());
	postData->AddText("name",level.GetName().c_str());
	postData->AddText("nothumb", "y");

	sprintf_s(IdString, 49, "%d", level.GetCustomData().size());
	postData->AddText("customfields", IdString);

	const CustomData& customData = level.GetCustomData();
	CustomData::const_iterator it = customData.begin();
	int fieldNumber = 0;
	for (; it != customData.end(); it++)
	{
		char buff[10];
		sprintf_s(buff,9,"%d", fieldNumber);
		std::string ckey("ckey");
		std::string cdata("cdata");
		ckey += buff;
		cdata += buff;

		postData->AddText(ckey.c_str(), it->first.c_str());
		postData->AddText(cdata.c_str(), it->second.c_str());
	}

	gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CPlayerLevels::SaveLevelComplete), postData);
	
}
Exemplo n.º 6
0
void mustache_spec_parse_partials(yaml_document_t * document, yaml_node_t * node, mustache::Node::Partials * partials)
{
  if( node->type != YAML_MAPPING_NODE ) {
    return;
  }
  
  mustache::Mustache mustache;
  std::string ckey;
  yaml_node_pair_t * pair;

  for( pair = node->data.mapping.pairs.start; pair < node->data.mapping.pairs.top; pair++ ) {
    yaml_node_t * keyNode = yaml_document_get_node(document, pair->key);
    yaml_node_t * valueNode = yaml_document_get_node(document, pair->value);
    char * keyValue = reinterpret_cast<char *>(keyNode->data.scalar.value);
    char * valueValue = reinterpret_cast<char *>(valueNode->data.scalar.value);
    
    std::string ckey(keyValue);
    std::string tmpl(valueValue);
    mustache::Node node;

    partials->insert(std::make_pair(ckey, node));
    mustache.tokenize(&tmpl, &(*partials)[ckey]);
  }
}
Exemplo n.º 7
0
SLevelListPtr CPlayerLevels::List( const std::string& mode, 
	int page, int perPage,
	bool includeData, bool includeThumbs,
	const CustomData& customFilter )
{
	std::string modeSafe = mode.empty() ? "popular" : (mode == "newest" || mode == "popular" ? mode : "popular");
	char dataSafe = includeData ? 'y': 'n';
	char thumSafe = includeThumbs ? 'y': 'n';

	
	
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kPlayerLevelListUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelListUrl2 +
		IdString + kPlayerLevelListUrl3 + modeSafe;
	sprintf_s(IdString,49,"%d", page);
	url += kPlayerLevelListUrl4 + page;
	sprintf_s(IdString,49,"%d", perPage);
	url += kPlayerLevelListUrl5; url += IdString;
	url += kPlayerLevelListUrl6;
	url += dataSafe;
	url += kPlayerLevelListUrl7;
	url += thumSafe;
	sprintf_s(IdString,49,"%d", customFilter.size());
	url += kPlayerLevelListUrl10;
	url += IdString;

	CPost postData;

	if(!customFilter.empty())
	{
		int fieldNumber = 0;
		CustomData::const_iterator  it = customFilter.begin();
		for(; it != customFilter.end(); it++)
		{
			char buff[10];
			sprintf_s(buff,9,"%d", fieldNumber);
			std::string ckey("ckey");
			std::string cdata("cdata");
			ckey += buff;
			cdata += buff;
			
			postData.AddText(ckey.c_str(), it->first.c_str());
			postData.AddText(cdata.c_str(), it->second.c_str());
		}
	}
	CPlaytomicResponsePtr response = gConnectionInterface->PerformSyncRequest(url.c_str(), &postData);
	SLevelListPtr returnList( new SLevelList);
	returnList->sErrorCode = response->ResponseError();
	returnList->sSucceded = response->ResponseSucceded();
	if (!returnList->sSucceded)
	{
		return returnList;
	}
	FData	levelArray(Json::arrayValue);

	const FData& queryData = response->ResponseData();

	FData ScoreList;


	levelArray = queryData.get("Levels", levelArray);

	
	FData value;
	value = queryData.get("NumLevels", value);
	for (size_t i = 0; i < levelArray.size(); i++)
	{
		value = levelArray[(int)i].get("LevelId", value);

	
		AddLevel(levelArray[(int)i], value.asString(), returnList->sLevelList);
	}
	return returnList;
}
Exemplo n.º 8
0
SSCoreTablePtr CLeaderboard::List( const std::string& tableName, bool highest, const std::string& mode, int page, int perPage,const CustomData& customFilter )
{
	char IdString[50];
	sprintf_s(IdString,49,"%d",gPlaytomic->GameId());
	std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrlList +
		IdString + kLeaderboardUrl3;

	CPost postData;
	postData.AddText("url", gPlaytomic->GetSourceUrl().c_str());
	postData.AddText("table", tableName.c_str());
	postData.AddText("highest", highest ? "y": "n");
	postData.AddText("mode", mode.c_str());
	char buff[300];
	sprintf_s(buff,299,"%d", page);
	postData.AddText("page", buff);
	sprintf_s(buff, 299,"%d", perPage);
	postData.AddText("perpage", buff);
	sprintf_s(buff, 299,"%d", customFilter.size());
	postData.AddText("numfilters", buff);

	if(customFilter.size() > 0)
	{
		int fieldNumber = 0;
		CustomData::const_iterator it = customFilter.begin();
		for(;it != customFilter.end(); it++)
		{
			sprintf_s(buff,299,"%d", fieldNumber);
			std::string ckey("ckey");
			ckey += buff;
			std::string cdata("cdata");
			cdata += buff;
			std::string value = it->second;
			fieldNumber++;

			postData.AddText(ckey.c_str(), it->first.c_str() );
			postData.AddText(cdata.c_str(), it->second.c_str());
		}		
	}


	CPlaytomicResponsePtr request = gConnectionInterface->PerformSyncRequest(url.c_str(),&postData);

	SSCoreTablePtr returnScores(new SSCoreTable);
	returnScores->sErrorCode = request->ResponseError();
	if(!request->ResponseSucceded())
	{
		returnScores->sSucceded = false;
		
		return returnScores;
	}
	returnScores->sSucceded = true;
	FData	scoreTable(Json::arrayValue);

	const FData& queryData = request->ResponseData();

	FData ScoreList;


	ScoreList = queryData.get("Scores", ScoreList);
	
	FData value;
	value = queryData.get("NumScores", value);
	returnScores->sScoreCount = value.asInt();
	for (size_t i = 0; i < ScoreList.size(); i++)
	{
		FData currentScore;

		currentScore = ScoreList[(int)i];

		value = currentScore.get("Name", value);
		std::string userName = value.asString();
		value = currentScore.get("Points", value);

		int points = value.asInt();

		value = currentScore.get("RDate",value);
		std::string relativeDate = value.asString();
        
        value = currentScore.get("SDate",value);
        std::string date(value.asString());

		value = currentScore.get("Rank", value);
		int rank = value.asInt();


		value = currentScore.get("CustomData", value);
		
		Json::ValueIterator it = value.begin();
		CustomData customData;
		for(; it != value.end(); it++)
		{
			customData.insert(std::make_pair((*it).asString(), (*it).asString()));
		}

		returnScores->sScoreList.push_back(CScore(userName, points, date, relativeDate, customData, rank));
	}
	
	return returnScores;
}
Exemplo n.º 9
0
/**
 * Creates a randomly generated city.
 */
void City::Generate(void) {
    for(int i = 0; i < CITY_W; i++) {
        for(int j = 0; j < CITY_H; j++) {
            hmap[i][j] = 1;
            if(i == 0 || j == 0 || i == CITY_W-1 || j == CITY_H-1) {
                hmap[i][j] = 0;
            }
        }
    }

    // Subdivide the place with streets (0 = a tile of street)
    int max_divisions = CITY_W*CITY_H/10;
    int divisions = 0;
    int min_spread = 2;

    int max_tries = CITY_W*CITY_H;

    while(max_tries > 0 && divisions < max_divisions) {

        int divx = rand()%CITY_W;
        int divy = rand()%CITY_H;

        // let's see if the nearest tiles are not street already
        int street_check = 1;


        for(int i = divx - min_spread; i < divx + min_spread; i++) {
            for(int j = divy - min_spread; j < divy + min_spread; j++) {
                if(i >= 0 && j >= 0 && i < CITY_W && j < CITY_H) {
                    street_check *= hmap[i][j];
                }
            }
        }

        if(street_check == 0) {
            max_tries--;
            continue;
        }


        for(int dir = 0; dir < 4; dir ++) {
            int cx = divx;
            int cy = divy;

            int mxr = CITY_W > CITY_H ? CITY_W : CITY_H;

            while(mxr > 0) {
                // bumped into a street or border?
                if(cx < 0 || cy < 0 || cx >= CITY_W || cy >= CITY_H
                    || ( hmap[cx][cy] == 0 && (cx != divx || cy != divy) )) {
                    break;
                }

                // mark the tile as street
                hmap[cx][cy] = 0;

                // step accordingly (too haxy?)
                cx += (dir+1)%2 * (1 - int(dir + .5)%3);
                cy += (dir+2)%2 * (1 - int(dir + 2.5)%3);

                mxr --;
            }
        }
        divisions++;
        max_tries--;
    }

    // Come up with some heights for the remaining buildings between streets

    for(int i = 0; i < CITY_W; i++) {
        for(int j = 0; j < CITY_H; j++) {

            // Select a random height for the building, min 2
            int height = 1+rand()%12;

            int si, sj;
            for(si = i; si < CITY_W; si++) {
                for(sj = j; sj < CITY_H; sj++) {
                    if(hmap[si][sj] != 1) {
                        break;
                    }
                    hmap[si][sj] = height;
                }
            }
        }
    }

    std::map<int, Block*> cache;

    // Make bloxxx out of the height data!
    for(int i = 0; i < CITY_W; i++) {
      for(int j = 0; j < CITY_H; j++) {
        for(int h = 0; h < getHeight(i,j); h++) {
          Block * block = new Block(world, i, h, j, 1, 1, 1);
          cache[ckey(i, j, h)] = block;
          blocks.push_back(block);
          if (h == 0) {
            btPoint2PointConstraint * c = new btPoint2PointConstraint(
                  *block->body, btVector3(0, -0.5, 0));
            block->body->addConstraintRef(c);
            world.addConstraint(c, false);
          } else if (h > 0) {
            Block *bottom = *(blocks.end() - 2);
            btQuaternion a;
            a.setRotation(btVector3(0, 0, 1), 3.14159265358979/2);
            btSliderConstraint * c = new btSliderConstraint(
                  *bottom->body, *block->body,
                  btTransform(a, btVector3(0, 0, 0)),
                  btTransform(a, btVector3(0, 0, 0)), true);
            c->setLowerLinLimit(1);
            c->setUpperLinLimit(1);
            block->body->addConstraintRef(c);
            world.addConstraint(c, true);
          }

          Block* left = cache[ckey(i-1, j, h)];
          Block* back = cache[ckey(i, j-1, h)];
          if(left) {
            btQuaternion a(0, 0, 0, 1);
            btSliderConstraint * c = new btSliderConstraint(
                  *left->body, *block->body,
                  btTransform::getIdentity(), btTransform::getIdentity(),
                  true);
            c->setLowerLinLimit(1);
            c->setUpperLinLimit(1);
            block->body->addConstraintRef(c);
            world.addConstraint(c, true);
          }
          if(back) {
            btQuaternion a;
            a.setRotation(btVector3(0, 1, 0), 3.14159265358979/2);
            btSliderConstraint * c = new btSliderConstraint(
                  *block->body, *back->body,
                  btTransform(a, btVector3(0, 0, 0)),
                  btTransform(a, btVector3(0, 0, 0)), true);
            c->setLowerLinLimit(1);
            c->setUpperLinLimit(1);
            block->body->addConstraintRef(c);
            world.addConstraint(c, true);
          }
        }
      }
    }

}