public AddScoreResponse Add([FromBody] AddScoreRequest request) { var response = new AddScoreResponse(); try { if (request == null) { throw new Exception("request is null - input format may be incorrect"); } if (request.publicKey != PublicKey) { throw new Exception("invalid access key"); } if (string.IsNullOrEmpty(request.game)) { throw new Exception("no game was specified"); } if (string.IsNullOrEmpty(request.name)) { throw new Exception("no player name was specified"); } if (request.score <= 0) { throw new Exception("invalid score: score must be >= 0"); } response.scoreId = highScores.AddScore(request.game, request.name, request.score, request.date); response.status = 0; } catch (Exception ex) { response.status = 1; response.message = ex.ToString(); } return(response); }
/// Called after a score has successfully been posted to ChilliConnect leaderboard. /// NOTE: The score returned here is the score that will be displayed on the leaderboard and not necessarily /// the score just posted. /// private void OnScoreAdded(AddScoreResponse response) { Debug.Log(string.Format("Player's high score {0}. Player is {1}/{2} on global leaderboard", response.Score, response.GlobalRank, response.GlobalTotal)); OnScorePosted(); }