예제 #1
0
void Tracker::AddResult( GameMode mode, Outcome outcome, GoingOrder order, Class ownClass, Class opponentClass,
    const CardHistoryList& historyCardList, int durationInSeconds, int rank, int legend )
{
  if( mode == MODE_SOLO_ADVENTURES ) {
    LOG( "Ignore solo adventure" );
    return;
  }

  if( mode == MODE_TAVERN_BRAWL ) {
    LOG( "Ignore tavern brawl" );
    return;
  }

#ifdef _DEBUG
  string cardHistoryOutput;
  for( CardHistoryList::const_iterator it = historyCardList.begin(); it != historyCardList.end(); ++it ) {
    cardHistoryOutput += (*it).player == PLAYER_SELF ? "SELF " : "OPPONENT ";
    cardHistoryOutput += (*it).cardId + "\n";
  }
  DEBUG( "Card History: %s", cardHistoryOutput.c_str() );
#endif

  if( outcome == OUTCOME_UNKNOWN ) {
    mUnknownOutcomeCount++;
    LOG( "Outcome unknown. Skip result" );
    return;
  }

  if( mode == MODE_UNKNOWN ) {
    mUnknownModeCount++;
    LOG( "Mode unknown. Skip result" );
    return;
  }

  if( order == ORDER_UNKNOWN ) {
    mUnknownOrderCount++;
    LOG( "Order unknown. Skip result" );
    return;
  }

  if( ownClass == CLASS_UNKNOWN ) {
    mUnknownClassCount++;
    LOG( "Own Class unknown. Skip result" );
    return;
  }

  if( opponentClass == CLASS_UNKNOWN ) {
    mUnknownOpponentCount++;
    LOG( "Class of Opponent unknown. Skip result" );
    return;
  }

  mSuccessfulResultCount++;

  LOG( "Upload %s %s vs. %s as %s. Went %s",
      MODE_NAMES[ mode ],
      OUTCOME_NAMES[ outcome ],
      CLASS_NAMES[ opponentClass ],
      CLASS_NAMES[ ownClass ],
      ORDER_NAMES[ order ] );

  QtJson::JsonObject result;
  result[ "coin" ]     = ( order == ORDER_SECOND );
  result[ "hero" ]     = CLASS_NAMES[ ownClass ];
  result[ "opponent" ] = CLASS_NAMES[ opponentClass ];
  result[ "win" ]      = ( outcome == OUTCOME_VICTORY );
  result[ "mode" ]     = MODE_NAMES[ mode ];
  result[ "duration" ] = durationInSeconds;

  if( mode == MODE_RANKED && rank != RANK_UNKNOWN && legend == LEGEND_UNKNOWN ) {
    result[ "rank" ] = rank;
  }
  if( mode == MODE_RANKED && legend != LEGEND_UNKNOWN ) {
    result[ "legend" ] = legend;
  }

  QtJson::JsonArray card_history;
  for( CardHistoryList::const_iterator it = historyCardList.begin(); it != historyCardList.end(); ++it ) {
    QtJson::JsonObject item;
    item[ "turn" ] = (*it).turn;
    item[ "player" ] = (*it).player == PLAYER_SELF ? "me" : "opponent";
    item[ "card_id" ] = (*it).cardId.c_str();
    card_history.append(item);
  }
  result[ "card_history" ] = card_history;

  QtJson::JsonObject params;
  params[ "result" ] = result;

  // Some metadata to find out room for improvement
  QtJson::JsonArray meta;

  meta.append( mSuccessfulResultCount );
  meta.append( mUnknownOutcomeCount );
  meta.append( mUnknownModeCount );
  meta.append( mUnknownOrderCount );
  meta.append( mUnknownClassCount );
  meta.append( mUnknownOpponentCount );
  meta.append( Hearthstone::Instance()->Width() );
  meta.append( Hearthstone::Instance()->Height() );
  meta.append( VERSION );
  meta.append( PLATFORM );

  params[ "_meta" ] = meta;

  QByteArray data = QtJson::serialize( params );

  QNetworkReply *reply = AuthPostJson( "/profile/results.json", data );
  connect( reply, SIGNAL( finished() ), this, SLOT( AddResultHandleReply() ) );
}
void FileSystemController::service(HttpRequest& request, HttpResponse& response)
{
	if (!CheckCreditinals(request, response))
	{
		return;
	}

	QString method = request.getMethod();

	if (method.compare("GET", Qt::CaseInsensitive) == 0)
	{
		QString currentPath = request.getParameter("currentPath");
		currentPath = QUrl::fromPercentEncoding(currentPath.toUtf8());
		QtJson::JsonArray respJson;

		if (!currentPath.isEmpty())
		{
			QDir pathDir(currentPath);

			if (pathDir.exists())
			{
				QStringList subdirsList = pathDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);

				for (int i = 0; i < subdirsList.count(); i++)
				{
					QtJson::JsonObject dir;
					dir["type"] = "dir";
					dir["name"] = subdirsList[i];
					respJson.append(dir);
				}
			}
			else
			{
				QtJson::JsonObject errObj;
				errObj["type"] = "err";
				errObj["msg"] = "Path doesnot exist";
				respJson.append(errObj);
			}
		}
		else
		{
			QList<QStorageInfo> volumes = QStorageInfo::mountedVolumes();

			for (int i = 0; i < volumes.count(); i++)
			{
				QtJson::JsonObject drive;
				drive["type"] = "drive";
				drive["freeSpace"] = StaticHelpers::toKbMbGb(volumes[i].bytesFree());
				drive["size"] = StaticHelpers::toKbMbGb(volumes[i].bytesTotal());
				drive["name"] = volumes[i].rootPath();
				respJson.append(drive);
			}
		}

		response.setHeader("Content-Type", "application/json");
		response.write(QtJson::serialize(respJson));
	}
	else
	{
		response.setStatus(405, "Method Not Allowed");
		response.write("<BODY><h3>405 Method Not Allowed.</h3>");
		response.write("</BODY>");
	}
}