void ScoreLoopThread::SubmitScore(AppData_t *app, double result, unsigned int mode) {
	qDebug() << "Submitting score " << result;
	/* Create a ScoreController */
	SC_Error_t rc = SC_Client_CreateScoreController(app->client, &app->scoreController, SubmitScoreCompletionCallback, app);
	if (rc != SC_OK) {
		HandleError(app, rc);
		return;
	}

	/* Create and configure the score */
	rc = SC_Client_CreateScore(app->client, &app->score);
	if (rc != SC_OK) {
		SC_ScoreController_Release(app->scoreController); /* Cleanup Controller */
		HandleError(app, rc);
		return;
	}
	SC_Score_SetLevel(app->score, result);
	SC_Score_SetResult(app->score, result * 100);
	SC_Score_SetMode(app->score, mode);

	/* Submit the score */
	rc = SC_ScoreController_SubmitScore(app->scoreController, app->score);
	if (rc != SC_OK) {
		SC_ScoreController_Release(app->scoreController); /* Cleanup Controller */
		SC_Score_Release(app->score); /* Cleanup Score */
		HandleError(app, rc);
		return;
	}
	qDebug() << "Submitting Score...";
}
示例#2
0
void CScores::DoSubmitScore()
{
	unsigned int aMode = 1;	
	unsigned int aLevel = 1;
	double aScore = (double)g_localhighscore;
	double aMinorResult = (double)s3eDeviceGetInt(S3E_DEVICE_OS); // Save OS type as Minor Result
	
	/* Create the score and set score data */
	SC_Score_h score;
	
	SC_Error_t retCode = SC_Score_New(&score);
	if (retCode == SC_OK) {
		SC_Score_SetResult(score, aScore);
		SC_Score_SetMode(score, aMode);
		SC_Score_SetLevel(score, aLevel);
		SC_Score_SetMinorResult(score, aMinorResult);

		retCode = SC_ScoreController_SubmitScore(m_scoreController, score);
		// See OnRequestSuccessSubmit()
	}
	
	/* SC_ScoreController_SubmitScore takes the ownership, we can safely release it */
	SC_Score_Release(score);
	
	if (retCode != SC_OK) {
		OnRequestFailed(retCode);
	}
}
void ScoreLoopThread::CreateChallenge(AppData_t *app, SC_Money_h stake, double result, unsigned int mode) {
	SC_Error_t rc;
	SC_Challenge_h challenge;
	SC_Score_h score;

	/* Create a ChallengeController */
	rc = SC_Client_CreateChallengeController(app->client, &app->challengeController, CreateChallengeCompletionCallback, app);
	if (rc != SC_OK) {
		HandleError(app, rc);
		return;
	}

	/* Create a Challenge */
	rc = SC_Client_CreateChallenge(app->client, stake, NULL, mode, 0, &challenge);
	if (rc != SC_OK) {
		SC_ChallengeController_Release(app->challengeController); /* Cleanup Controller */
		HandleError(app, rc);
		return;
	}

	/* Assign challenge to controller */
	rc = SC_ChallengeController_SetChallenge(app->challengeController, challenge);
	SC_Challenge_Release(challenge); /* Not needed anymore, so cleanup */
	if (rc != SC_OK) {
		SC_ChallengeController_Release(app->challengeController); /* Cleanup Controller */
		HandleError(app, rc);
		return;
	}

	/* Create a Score object with given result */
	rc = SC_Client_CreateScore(app->client, &score);
	if (rc != SC_OK) {
		SC_ChallengeController_Release(app->challengeController); /* Cleanup Controller */
		HandleError(app, rc);
		return;
	}
	rc = SC_Score_SetResult(score, result);
	if (rc != SC_OK) {
		SC_ChallengeController_Release(app->challengeController); /* Cleanup Controller */
		SC_Score_Release(score); /* Cleanup Score */
		HandleError(app, rc);
		return;
	}

	/* Submit Challenge for score */
	rc = SC_ChallengeController_SubmitChallengeScore(app->challengeController, score);
	SC_Score_Release(score); /* Not needed anymore, so cleanup */
	if (rc != SC_OK) {
		SC_ChallengeController_Release(app->challengeController); /* Cleanup Controller */
		HandleError(app, rc);
		return;
	}
	qDebug() << "Creating Challenge...";
}
void ScoreLoopThread::SubmitScoreCompletionCallback(void *userData, SC_Error_t completionStatus) {
	/* Get the application from userData argument */
	AppData_t *app = (AppData_t *) userData;

	SC_Error_t rc ;
	/* Check completion status */
	if (completionStatus != SC_OK) {
		SC_ScoreController_Release(app->scoreController); /* Cleanup Controller */
		SC_Score_Release(app->score); /* Cleanup Score */
		HandleError(app, completionStatus);
		return;
	}
	qDebug() << "Done submitting Score";

	/* Cleanup Controller */
	SC_ScoreController_Release(app->scoreController);

	SC_Score_h lastScore;

	rc = SC_Client_CreateScore(app->client, &lastScore);
	if (rc != SC_OK) {
		HandleError(app, rc);
		return;
	}
	SC_Score_SetLevel(lastScore, SC_Score_GetLevel(app->score));
	SC_Score_SetResult(lastScore, SC_Score_GetResult(app->score));
	SC_Score_SetMode(lastScore, SC_Score_GetMode(app->score));

	ScoreData_t scoreData;
	scoreData.score = lastScore;

	emit(instance()->SubmitScoreCompleted(&scoreData));

	/* Cleanup Score */
	SC_Score_Release(app->score);
}