コード例 #1
0
BOOL AchievementSet::FetchFromWebBlocking( GameID nGameID )
{
	//	Can't open file: attempt to find it on SQL server!
	PostArgs args;
	args['u'] = RAUsers::LocalUser().Username();
	args['t'] = RAUsers::LocalUser().Token();
	args['g'] = std::to_string( nGameID );
	args['h'] = g_bHardcoreModeActive ? "1" : "0";

	Document doc;
	if( RAWeb::DoBlockingRequest( RequestPatch, args, doc ) && 
		doc.HasMember( "Success" ) && 
		doc[ "Success" ].GetBool() && 
		doc.HasMember( "PatchData" ) )
	{
		const Value& PatchData = doc[ "PatchData" ];

		//const std::string& sMinVer = PatchData["MinVer"].GetString();
		//const long nMinVerRequired = strtol( sMinVer.substr( 2 ).c_str(), NULL, 10 );
		
		//const long CURRENT_VER = strtol( std::string( g_sClientVersion ).substr( 2 ).c_str(), nullptr, 10 );
		//if( CURRENT_VER < nMinVerRequired )
		//{
		//	//	Client version too old!

		//	char buffer[4096];
		//	sprintf_s( buffer, 4096, 
		//		"Client version of 0.%03d is too old for the latest patch format.\r\n"
		//		"Version 0.%03d or greater required.\r\n"
		//		"Visit " RA_HOST " for a more recent version? ",
		//		CURRENT_VER,
		//		nMinVerRequired );

		//	if( MessageBox( nullptr, buffer, "Client out of date!", MB_YESNO ) == IDYES )
		//	{
		//		sprintf_s( buffer, 4096, "http://" RA_HOST "/download.php" );

		//		ShellExecute( NULL,
		//			"open",
		//			buffer,
		//			NULL,
		//			NULL,
		//			SW_SHOWNORMAL );
		//	}
		//	else
		//	{
		//		//MessageBox( nullptr, "Cannot load achievements for this game.", "Error", MB_OK );
		//	}

		//	return FALSE;
		//}
		//else
		{
			SetCurrentDirectory( Widen( g_sHomeDir ).c_str() );
			FILE* pf = nullptr;
			fopen_s( &pf, std::string( RA_DIR_DATA + std::to_string( nGameID ) + ".txt" ).c_str(), "wb" );
			if( pf != nullptr )
			{
				FileStream fs( pf );
				Writer<FileStream> writer( fs );
				PatchData.Accept( writer );
				fclose( pf );
				return TRUE;
			}
			else
			{
				ASSERT( !"Could not open patch file for writing?" );
				RA_LOG( "Could not open patch file for writing?" );
				return FALSE;
			}
		}
	}
	else
	{
		//	Could not connect...
		PopupWindows::AchievementPopups().AddMessage( 
			MessagePopup( "Could not connect to " RA_HOST_URL "...", "Working offline...", PopupInfo ) ); //?

		return FALSE;
	}
}
コード例 #2
0
/* ****************************************************************************
*
* parseBatchQuery - 
*/
std::string parseBatchQuery(ConnectionInfo* ciP, BatchQuery* bqrP)
{
  Document document;

  document.Parse(ciP->payload);

  if (document.HasParseError())
  {
    ErrorCode ec;

    alarmMgr.badInput(clientIp, "JSON Parse Error");
    ec.fill(ERROR_STRING_PARSERROR, "Errors found in incoming JSON buffer");
    ciP->httpStatusCode = SccBadRequest;

    return ec.toJson(true);
  }

  if (!document.IsObject())
  {
    ErrorCode ec;

    alarmMgr.badInput(clientIp, "JSON Parse Error");
    ec.fill("BadRequest", "JSON Parse Error");
    ciP->httpStatusCode = SccBadRequest;

    return ec.toJson(true);
  }
  else if (document.ObjectEmpty())
  {
    ErrorCode ec;

    alarmMgr.badInput(clientIp, "Empty JSON payload");
    ec.fill("BadRequest", "empty payload");
    ciP->httpStatusCode = SccBadRequest;

    return ec.toJson(true);
  }
  else if (!document.HasMember("entities") && !document.HasMember("attributes") && !document.HasMember("scopes"))
  {
    ErrorCode ec;

    alarmMgr.badInput(clientIp, "Invalid JSON payload, no relevant fields found");
    ec.fill("BadRequest", "Invalid JSON payload, no relevant fields found");
    ciP->httpStatusCode = SccBadRequest;

    return ec.toJson(true);
  }

  for (Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter)
  {
    std::string name   = iter->name.GetString();
    std::string type   = jsonParseTypeNames[iter->value.GetType()];

    if (name == "entities")
    {
      std::string r = parseEntityVector(ciP, iter, &bqrP->entities, false);  // param 4: attributes are NOT allowed in payload

      if (r != "OK")
      {
        ErrorCode ec("BadRequest", r);

        alarmMgr.badInput(clientIp, r);
        ciP->httpStatusCode = SccBadRequest;
        return ec.toJson(true);
      }
    }
    else if (name == "attributes")
    {
      std::string r = parseAttributeList(ciP, iter, &bqrP->attributeV);

      if (r != "OK")
      {
        ErrorCode ec("BadRequest", r);

        alarmMgr.badInput(clientIp, r);
        ciP->httpStatusCode = SccBadRequest;
        return ec.toJson(true);
      }
    }
    else if (name == "scopes")
    {
      std::string r = parseScopeVector(ciP, iter, &bqrP->scopeV);

      if (r != "OK")
      {
        ErrorCode ec("BadRequest", r);

        alarmMgr.badInput(clientIp, r);
        ciP->httpStatusCode = SccBadRequest;
        return ec.toJson(true);
      }
    }
    else
    {
      std::string  description = std::string("Unrecognized field in JSON payload: /") + name + "/";
      ErrorCode    ec("BadRequest", description);

      alarmMgr.badInput(clientIp, description);
      ciP->httpStatusCode = SccBadRequest;

      return ec.toJson(true);
    }
  }

  return "OK";
}
コード例 #3
0
ファイル: rectanglebuilder.cpp プロジェクト: mhbelouni/shared
  bool parse_document(const Document& document, std::vector<rectangle>& input_rectangle)
  {
    if(!document.IsObject())
    {
      return false;
    }

    // check rects array
    if(document.HasMember(RECTANGLES_KEY) && document[RECTANGLES_KEY].IsArray())
    {
      //iterate and validate each element
      const Value& rects = document[RECTANGLES_KEY];
      for (SizeType count = 0; count < rects.Size(); count++)
      {
        //check x
        origin_t x = 0;
        if(rects[count].HasMember(RECTANGLES_X) && rects[count][RECTANGLES_X].IsInt())
        {
          x = rects[count][RECTANGLES_X].GetInt();
        }
        else
        {
          print_error(RECTANGLES_X);
          return false;
        }

        //check y
        origin_t y = 0;
        if(rects[count].HasMember(RECTANGLES_Y) && rects[count][RECTANGLES_Y].IsInt())
        {
          y = rects[count][RECTANGLES_Y].GetInt();
        }
        else
        {
          print_error(RECTANGLES_Y);
          return false;
        }

        //check w
        distance_t w = 0;
        if(rects[count].HasMember(RECTANGLES_W) && rects[count][RECTANGLES_W].IsUint())
        {
          w = rects[count][RECTANGLES_W].GetUint();
        }
        else
        {
          print_error(RECTANGLES_W);
          return false;
        }

        //check h
        distance_t h = 0;
        if(rects[count].HasMember(RECTANGLES_H) && rects[count][RECTANGLES_H].IsUint())
        {
          h = rects[count][RECTANGLES_H].GetUint();
        }
        else
        {
          print_error(RECTANGLES_H);
          return false;
        }

        input_rectangle.push_back(rectangle(x, y, w, h, std::to_string(static_cast<ullong_int_t>(count+1))));
      }
    }
    else
    {
      print_error(RECTANGLES_KEY);
      return false;
    }

    return true;
  }