private void ResumeSession() { var cotc = FindObjectOfType <CotcGameObject>(); cotc.GetCloud().Done(cloud => { Cloud.ResumeSession( gamerId: userStorage.GamerId, gamerSecret: userStorage.GamerSecretID) .Done(gamer => { Gamer = gamer; Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")"); Debug.Log("Login data: " + gamer); Debug.Log("Server time: " + gamer["servertime"]); var loginUI = FindObjectOfType <LoginUI>(); loginUI.updateUI(); var profile = FindObjectOfType <ProfileScript>(); if (profile != null) { profile.UpdateProfile(); } }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }); }
public void SignIn(string _id, string _pwd, Action <string, string> OnResult = null, Action <string, string> OnFailed = null) { master.Cloud.ResumeSession( gamerId: _id, gamerSecret: _pwd) .Done(gamer => { if (IsEmail(_id)) { PlayerPrefs.SetInt(KEY_NETWORK, 1); } else { PlayerPrefs.SetInt(KEY_NETWORK, 0); } PlayerPrefs.SetString(KEY_ID, _id); PlayerPrefs.SetString(KEY_PWD, _pwd); PlayerPrefs.Save(); loggedGamer = gamer; OnResult?.Invoke(_id, _pwd); OnLogged?.Invoke(); }, ex => { Debug.LogError("Login failed: " + ex.ToString()); LoginAnonymously(); OnFailed?.Invoke(_id, _pwd); CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }
public void LoginToAccount(string network, string email, string password) { var cotc = FindObjectOfType <CotcGameObject>(); cotc.GetCloud().Done(cloud => { Cloud.Login( network: network, networkId: email, networkSecret: password) .Done(gamer => { Gamer = gamer; SaveGamer(gamer); Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")"); Debug.Log("Login data: " + gamer); Debug.Log("Server time: " + gamer["servertime"]); var profile = FindObjectOfType <ProfileScript>(); profile.UpdateProfile(); var loginUI = FindObjectOfType <LoginUI>(); loginUI.updateUI(); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }); }
public void ChangeEmail(string _newMail, Action <string> OnResult = null, Action OnFailed = null) { if (!IsLogged) { Debug.LogError("Not logged"); return; } if (!IsRegisteredEmail) { Debug.LogError("Not registered email"); return; } loggedGamer.Account.ChangeEmailAddress(_newMail) .Done(changeEmailRes => { PlayerPrefs.SetString(KEY_ID, _newMail); PlayerPrefs.Save(); OnResult?.Invoke(_newMail); }, ex => { OnFailed?.Invoke(); CotcException error = (CotcException)ex; Debug.LogError("Failed to change e-mail: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
//Logout public void LogOut() { Cloud.Logout(Gamer) .Done(result => { Debug.Log("Logout succeeded"); if (Logout != null) { Logout(); //Prepapre ui cotcCanvas.gameObject.SetActive(true); ShowLogButton(true); displayInfoText.text = ""; playButton.gameObject.SetActive(false); EmailInput.text = ""; passwordInput.text = ""; //Prepare mouse Cursor.lockState = CursorLockMode.Confined; Cursor.visible = true; //Change bool isLog = false; isLogAno = false; } }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to logout: " + error.ErrorCode + " (" + error.HttpStatusCode + ")"); }); }
public void ResumeSession() { Cloud.ResumeSession( gamerId: "5873a117b69fa8c942c7df08", gamerSecret: "c3b7c6fab599919b0c24487bf46d0e6069472df0") .Done(gamer => DidLogin(gamer), ex => { CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }
private void SendScoreToLeaderboard() { Debug.Log("Total time = " + endCoutdown); Gamer.Scores.Domain("private").Post((long)endCoutdown, leaderboardName, ScoreOrder.LowToHigh, "Time", false) .Done(postScoreRes => { Debug.Log("Post score: " + postScoreRes.ToString()); }, ex => { CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
//Called by the Gamemanager when game end (post score + extra point if win) public void PostScore(int score) { LoggedGamer.Scores.Domain("private").Post(score, "EasterIslandScoreboard", ScoreOrder.HighToLow, "context for score", false) .Done(postScoreRes => { Debug.Log("Post score: " + postScoreRes.ToString()); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
public void GetListUsers(string _matchPattern, int _number, Action <PagedList <UserInfo> > OnResult = null, Action OnFailed = null, int _startIndex = 0) { master.Cloud.ListUsers(_matchPattern, _number, _startIndex) .Done(listUsersRes => { OnResult?.Invoke(listUsersRes); }, ex => { OnFailed?.Invoke(); CotcException error = (CotcException)ex; Debug.LogError("Failed to list users: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
private void LoginAnonym() { // Call the API method which returns an Promise<Gamer> (promising a Gamer result). // It may fail, in which case the .Then or .Done handlers are not called, so you // should provide a .Catch handler. Cloud.LoginAnonymously() .Then(gamer => DidLogin(gamer)) .Catch(ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }
public void CheckExistingMail(string _mail, Action <bool> OnResult = null, Action OnFailed = null) { master.Cloud.UserExists("email", _mail) .Done(userExistsRes => { OnResult?.Invoke(userExistsRes.Successful); }, ex => { OnFailed?.Invoke(); CotcException error = (CotcException)ex; Debug.LogError("Failed to check user: "******" (" + error.ErrorInformation + ")"); }); }
public void Login(Action afterLogin = null) { Cloud.LoginAnonymously().Then(gamer => { DidLogin(gamer); if (afterLogin != null) { afterLogin(); } }) .Catch(ex => { CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }
public void UpdateProfile() { print("update profile"); LoginScript.Gamer.Profile.Get() .Done(profileRes => { LoginScript.username = profileRes["displayName"]; profileName.text = LoginScript.username; }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not get profile data due to error: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); //Get current Gamer Profile }
//------------------------------------------------------- //REQUEST public void FindUsers() { Cloud.ListUsers("", 30, 0) .Done(listUsersRes => { foreach (var userInfo in listUsersRes) { Debug.Log("User: "******"Failed to list users: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
/// <summary> /// Return an exception (expected to be a CotcException) under the ExceptionError format. /// </summary> /// <param name="exception">The original Exception.</param> /// <param name="exceptionType">To set the exception type in case the exception is not of CotcException type or doesn't contain any server data. (optional)</param> public static ExceptionError GetExceptionError(Exception exception, string exceptionType = null) { // The exception should always be of the CotcException type CotcException cotcException = exception as CotcException; if ((cotcException != null) && (cotcException.ServerData != null)) { return(new ExceptionError(cotcException.ServerData["name"].AsString(), cotcException.ServerData["message"].AsString())); } else { return(new ExceptionError(string.IsNullOrEmpty(exceptionType) ? "UnknownException" : exceptionType, exception.ToString())); } }
public void PostScore(int score) { // currentGamer is an object retrieved after one of the different Login functions. loginScript.Gamer.Scores.Domain("private").Post(score, "normalMode", ScoreOrder.HighToLow, "Best score", false) .Done(postScoreRes => { GameObject.Find("Rank").GetComponent <Text>().text = "Rank: " + postScoreRes.Rank.ToString(); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
public void SendScore(float score, GameObject listOfScore) { Gamer.Scores.Domain("private").Post( (long)score, BASE_LEADERBOARD_KEY, ScoreOrder.HighToLow ).Done(postedScore => { Debug.Log("SCORE POSTED : " + postedScore.HasBeenSaved); SetLeaderboard(listOfScore); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
//------------------------------------------------------- //Leaderboard private void PrintLeaderboard() { Gamer.Scores.Domain("private").BestHighScores(leaderboardName, 5, 1) .Done(bestHighScoresRes => { //Print each score for (int i = 0; i < bestHighScoresRes.Count; i++) { string leaderboardText = "Name : " + bestHighScoresRes[i].GamerInfo["profile"]["displayName"] + " - Time : " + bestHighScoresRes[i].Value + " sec"; leaderboardPlayerText[i].text = leaderboardText; } }, ex => { CotcException error = (CotcException)ex; Debug.LogError("Could not get best high scores: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
void PostScore() { // currentGamer is an object retrieved after one of the different Login functions. if (Settings.difficulty == 0) { LoginFeatures.gamer.Scores.Domain("private").Post(Settings.wins, "Easy", ScoreOrder.HighToLow, "", false) .Done(postScoreRes => { Debug.Log("Post score: " + postScoreRes.ToString()); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); } if (Settings.difficulty == 1) { LoginFeatures.gamer.Scores.Domain("private").Post(Settings.wins, "Normal", ScoreOrder.HighToLow, "", false) .Done(postScoreRes => { Debug.Log("Post score: " + postScoreRes.ToString()); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); } if (Settings.difficulty == 2) { LoginFeatures.gamer.Scores.Domain("private").Post(Settings.wins, "Hard", ScoreOrder.HighToLow, "", false) .Done(postScoreRes => { Debug.Log("Post score: " + postScoreRes.ToString()); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not post score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); if (Settings.wins == 3) { SetAchievementData("Win-Hard"); } } }
private void GetLast() { Cloud.ResumeSession( gamerId: lastGamerID, gamerSecret: lastGamerSECRET) .Done(gamer => { Gamer = gamer; Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")"); Debug.Log("Login data: " + gamer); Debug.Log("Server time: " + gamer["servertime"]); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }
//Called by the MainMenuScript when login/Anonymous login is done public void SetUpScoreboard(TMPro.TMP_Text scoreboard) { scoreboard.text = ""; LoggedGamer.Scores.Domain("private").BestHighScores("EasterIslandScoreboard", 10, 1) .Done(bestHighScoresRes => { foreach (var score in bestHighScoresRes) { scoreboard.text += score.Rank + ". " + score.GamerInfo["profile"]["displayName"] + ": " + score.Value + '\n'; Debug.Log(score.Rank + ". " + score.GamerInfo["profile"]["displayName"] + ": " + score.Value); } }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not get best high scores: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
public void GetRank(float time) { if (!RequireGamer()) { return; } Gamer.Scores.Domain("private").GetRank(TimeToScore(time), "mode") .Done(getRankRes => { Debug.Log("Rank for score: " + getRankRes); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not get rank for score: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
//Called by MainMenuScript when logout button is used public void Logout() { Cloud.Logout(LoggedGamer).Done(result => { Debug.Log("Logout succeeded"); mms.LogedOut(); PlayerPrefs.DeleteKey("GamerId"); PlayerPrefs.DeleteKey("GamerSecret"); LoggedGamer = null; }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to logout: " + error.ErrorCode + " (" + error.HttpStatusCode + ")"); }); }
public void SetUserValue(string key, Bundle value) { if (connected) { Player.GamerVfs.Domain("private").SetValue(key, value) .Done(setUserValueRes => { Debug.Log("User data set: " + setUserValueRes.ToString()); GetMaxScoreValue(); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Could not set user data due to error: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); } }
public void ConvertAccount() { if (anoEmailInputField.text.Length == 0 || anoPasswordInputField.text.Length == 0) { displayAnoAccountInfoText.text = "Please, fill the email and password input field"; return; } //Try to convert if (!GamerIsConnected()) { return; } Gamer.Account.Convert( network: LoginNetwork.Email.ToString().ToLower(), networkId: anoEmailInputField.text, networkSecret: anoPasswordInputField.text) .Done(dummy => { displayAnoAccountInfoText.text = "Successfully converted account"; Debug.Log("Successfully converted account"); //hide convert button convertButtonAno.gameObject.SetActive(false); //Change bool isLogAno = false; //SaveFile SaveType player = new SaveType { networkType = Gamer["network"], playerId = Gamer["gamer_id"], playerSecret = Gamer["gamer_secret"], networkID = Gamer["networkid"], networkSecret = anoPasswordInputField.text }; string data = JsonUtility.ToJson(player); SaveFile(data); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; string myError = PrepareErrorMessage(error.ToString()); //print error message displayAnoAccountInfoText.text = "Failed to convert : " + myError; Debug.LogError("Failed to convert: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
public void GetMaxScoreValue() { if (connected) { Player.GamerVfs.Domain("private").GetValue("MaxScore") .Done(getUserValueRes => { MaxScore = getUserValueRes["result"]; Debug.Log("User data: " + MaxScore.ToString()); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.Log("Could not get user data due to error: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); } }
/// <summary> /// Log an exception (expected to be a CotcException) into the console. /// </summary> /// <param name="className">Name of the involved class.</param> /// <param name="methodName">Name of the involved method.</param> /// <param name="exception">The original Exception.</param> public static void LogCotcException(string className, string methodName, Exception exception) { // The exception should always be of the CotcException type CotcException cotcException = exception as CotcException; if (cotcException == null) { DebugLogs.LogError(string.Format("[CotcSdkTemplate:{0}] {1} exception ›› {2}", className, methodName, exception)); } else if ((cotcException.ServerData != null) && !string.IsNullOrEmpty(cotcException.ServerData.ToString())) { DebugLogs.LogError(string.Format("[CotcSdkTemplate:{0}] {1} exception ›› ({2}) {3}: {4} ›› {5}", className, methodName, cotcException.HttpStatusCode, cotcException.ErrorCode, cotcException.ErrorInformation, cotcException.ServerData)); } else { DebugLogs.LogError(string.Format("[CotcSdkTemplate:{0}] {1} exception ›› ({2}) {3}: {4}", className, methodName, cotcException.HttpStatusCode, cotcException.ErrorCode, cotcException.ErrorInformation)); } }
public void Logout() { var cotc = FindObjectOfType <CotcGameObject>(); cotc.GetCloud().Done(cloud => { Cloud.Logout(Gamer) .Done(result => { userStorage.GamerId = ""; userStorage.GamerSecretID = ""; DoLogin(); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to logout: " + error.ErrorCode + " (" + error.HttpStatusCode + ")"); }); }); }
public void ResetPassword(string _mail, Action OnResult = null, Action OnFailed = null) { //Email infos string from = "*****@*****.**"; string title = "Reset your password"; string body = "You can login with this shortcode: [[SHORTCODE]]"; master.Cloud.SendResetPasswordEmail(_mail, from, title, body) .Done(resetPasswordRes => { OnResult?.Invoke(); }, ex => { OnFailed?.Invoke(); CotcException error = (CotcException)ex; Debug.LogError("Short code sending failed due to error: " + error.ErrorCode + " (" + error.ErrorInformation + ")"); }); }
public void LoginAnonymous() { var cotc = FindObjectOfType <CotcGameObject>(); cotc.GetCloud().Done(cloud => { cloud.LoginAnonymously() .Done(gamer => { Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")"); Debug.Log("Login data: " + gamer); Debug.Log("Server time: " + gamer["servertime"]); canvasLogin.gameObject.SetActive(false); canvasSuccedLogin.gameObject.SetActive(true); }, ex => { // The exception should always be CotcException CotcException error = (CotcException)ex; Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")"); }); }); }