Example #1
0
        /// <summary>
        /// Login the gamer on a given network with specific credentials. (create a new account if it doesn't exist yet)
        /// </summary>
        /// <param name="network">Name of the network to use (lowercase from the LoginNetwork enum).</param>
        /// <param name="accountID">Identifier (email, ID, ...) of the gamer's account.</param>
        /// <param name="accountSecret">Secret (password, token, ...) of the gamer's account.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_Login(string network, string accountID, string accountSecret, Action <Gamer> OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            DebugLogs.LogVerbose(string.Format("void Backend_Login : {0} {1} {2}", network, accountID, accountSecret));

            // Need an initialized Cloud to proceed
            if (!CloudFeatures.IsCloudInitialized())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotSetup), ExceptionTools.notInitializedCloudErrorType));
                return;
            }

            // Call the API method which returns a Gamer result
            CloudFeatures.cloud.Login(network, accountID, accountSecret)
            // Result if everything went well
            .Done(delegate(Gamer loggedInGamer)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:LoginFeatures] Login success ›› Logged In Gamer: {0}", loggedInGamer));

                // Keep the Gamer's reference
                gamer = loggedInGamer;

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(loggedInGamer);
                }

                // Call the GamerLoggedIn event if any callback registered to it
                if (Event_GamerLoggedIn != null)
                {
                    Event_GamerLoggedIn(gamer);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("LoginFeatures", "Login", exception);
                }
            });
        }
Example #2
0
        /// <summary>
        /// Logout the current logged in gamer.
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_Logout(Action OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a Done result
            CloudFeatures.cloud.Logout(gamer)
            // Result if everything went well
            .Done(delegate(Done logoutDone)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:LoginFeatures] Logout success ›› Successful: {0}", logoutDone.Successful));

                // Discard the Gamer's reference
                gamer = null;

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess();
                }

                // Call the GamerLoggedOut event if any callback registered to it
                if (Event_GamerLoggedOut != null)
                {
                    Event_GamerLoggedOut();
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("LoginFeatures", "Logout", exception);
                }
            });
        }
Example #3
0
        /// <summary>
        /// Get the CotcSdk's Cloud instance.
        /// </summary>
        /// <param name="cotcGameObject">CotcSdk's CotcGameObject instance.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_GetCloud(CotcGameObject cotcGameObject, Action <Cloud> OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Call the API method which returns a Cloud result
            cotcGameObject.GetCloud()
            // Result if everything went well
            .Done(delegate(Cloud cloudInstance)
            {
                DebugLogs.LogVerbose("[CotcSdkTemplate:CloudFeatures] GetCloud success");

                // Keep the Cloud instance reference
                cloud = cloudInstance;

                // Register to the HttpRequestFailedHandler event
                cloud.HttpRequestFailedHandler = RetryFailedRequestOnce;

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(cloudInstance);
                }

                // Call the CloudInitialized event if any callback registered to it
                if (Event_CloudInitialized != null)
                {
                    Event_CloudInitialized(cloud);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("CloudFeatures", "GetCloud", exception);
                }
            });
        }
        /// <summary>
        /// Get the logged in gamer's referral code.
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_GenerateCode(Action <string> OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a string result
            LoginFeatures.gamer.Godfather.Domain(domain).GenerateCode()
            // Result if everything went well
            .Done(delegate(string referralCode)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:GodfatherFeatures] GenerateCode success ›› Referral Code: {0}", referralCode));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(referralCode);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("GodfatherFeatures", "GenerateCode", exception);
                }
            });
        }
        /// <summary>
        /// Get the value of the given key (or all keys if null or empty) associated to the current game.
        /// </summary>
        /// <param name="key">Name of the key to get.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_GetValue(string key, Action <Bundle> OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud to proceed
            if (!CloudFeatures.IsCloudInitialized())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotSetup), ExceptionTools.notInitializedCloudErrorType));
                return;
            }

            // Call the API method which returns a Bundle result
            CloudFeatures.cloud.Game.GameVfs.Domain(domain).GetValue(key)
            // Result if everything went well
            .Done(delegate(Bundle keysValues)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:GameVFSFeatures] GetValue success ›› Keys Values: {0}", keysValues));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(keysValues);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("GameVFSFeatures", "GetValue", exception);
                }
            });
        }
Example #6
0
        /// <summary>
        /// Set the relationship between the current logged in gamer and the given other gamer.
        /// </summary>
        /// <param name="gamerID">Identifier of the gamer with who to change the relationship.</param>
        /// <param name="relationship">Type of relationship to set.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="pushNotification">Message to send as notification if the target gamer is offline. (optional)</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_ChangeRelationshipStatus(string gamerID, FriendRelationshipStatus relationship, Action <Done, string, FriendRelationshipStatus> OnSuccess = null, Action <ExceptionError, string, FriendRelationshipStatus> OnError = null, PushNotification pushNotification = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType), gamerID, relationship);
                return;
            }

            // Call the API method which returns a Done result
            LoginFeatures.gamer.Community.Domain(domain).ChangeRelationshipStatus(gamerID, relationship, pushNotification)
            // Result if everything went well
            .Done(delegate(Done changeDone)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:CommunityFeatures] ChangeRelationshipStatus success ›› Successful: {0}", changeDone.Successful));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(changeDone, gamerID, relationship);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception), gamerID, relationship);
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("CommunityFeatures", "ChangeRelationshipStatus", exception);
                }
            });
        }
Example #7
0
        /// <summary>
        /// Get a list of gamers matching with the given match pattern (tested against display name and email).
        /// </summary>
        /// <param name="matchPattern">What users' display name or email must contain.</param>
        /// <param name="usersPerPage">Number of users to get per page.</param>
        /// <param name="usersOffset">Number of users to skip.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_ListUsers(string matchPattern, int usersPerPage, int usersOffset, Action <PagedList <UserInfo> > OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Need an initialized Cloud to proceed
            if (!CloudFeatures.IsCloudInitialized())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotSetup), ExceptionTools.notInitializedCloudErrorType));
                return;
            }

            // Call the API method which returns a PagedList<UserInfo> result
            CloudFeatures.cloud.ListUsers(matchPattern, usersPerPage, usersOffset)
            // Result if everything went well
            .Done(delegate(PagedList <UserInfo> usersList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:CommunityFeatures] ListUsers success ›› {0} user(s)", usersList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(usersList);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("CommunityFeatures", "ListUsers", exception);
                }
            });
        }
        /// <summary>
        /// Delete the given key (or all keys if null or empty) associated to the current logged in gamer.
        /// </summary>
        /// <param name="key">Name of the key to delete.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_DeleteValue(string key, Action <Done> OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a Done result
            LoginFeatures.gamer.GamerVfs.Domain(domain).DeleteValue(key)
            // Result if everything went well
            .Done(delegate(Done deleteDone)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:GamerVFSFeatures] DeleteValue success ›› Successful: {0}", deleteDone.Successful));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(deleteDone);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("GamerVFSFeatures", "DeleteValue", exception);
                }
            });
        }
Example #9
0
        /// <summary>
        /// Post a new transaction of the given currency for the current logged in gamer.
        /// </summary>
        /// <param name="transaction">Transaction currencies data under the Bundle format.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="transactionDescription">Description of the transaction. (optional)</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_Post(Bundle transaction, Action <TransactionResult> OnSuccess = null, Action <ExceptionError> OnError = null, string transactionDescription = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a TransactionResult result
            LoginFeatures.gamer.Transactions.Domain(domain).Post(transaction, transactionDescription)
            // Result if everything went well
            .Done(delegate(TransactionResult postedTransaction)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:TransactionFeatures] Post success ›› New Balance: {0}, Triggered Achievements Count: {1}", postedTransaction.Balance, postedTransaction.TriggeredAchievements.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(postedTransaction);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("TransactionFeatures", "Post", exception);
                }
            });
        }
Example #10
0
        /// <summary>
        /// Get the list of current logged in gamer's godchildren.
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_GetGodchildren(Action <NonpagedList <GamerInfo> > OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a NonpagedList<GamerInfo> result
            LoginFeatures.gamer.Godfather.Domain(domain).GetGodchildren()
            // Result if everything went well
            .Done(delegate(NonpagedList <GamerInfo> godchildrenList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:GodfatherFeatures] GetGodchildren success ›› {0} godchild(ren)", godchildrenList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(godchildrenList);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("GodfatherFeatures", "GetGodchildren", exception);
                }
            });
        }
Example #11
0
        /// <summary>
        /// Get the current logged in gamer's history of the given currency (or all currencies if null or empty).
        /// </summary>
        /// <param name="currencyName">Name of the currency to get.</param>
        /// <param name="transactionsPerPage">Number of transactions to get per page.</param>
        /// <param name="transactionsOffset">Number of transactions to skip.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_History(string currencyName, int transactionsPerPage, int transactionsOffset, Action <PagedList <Transaction> > OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a PagedList<Transaction> result
            LoginFeatures.gamer.Transactions.Domain(domain).History(currencyName, transactionsPerPage, transactionsOffset)
            // Result if everything went well
            .Done(delegate(PagedList <Transaction> transactionsList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:TransactionFeatures] History success ›› {0} transaction(s)", transactionsList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(transactionsList);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("TransactionFeatures", "History", exception);
                }
            });
        }
Example #12
0
        /// <summary>
        /// Get the next page of a previously obtained transaction page.
        /// </summary>
        /// <param name="transactions">Paged list of transactions.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_FetchNext(PagedList <Transaction> transactions, Action <PagedList <Transaction> > OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            if (transactions.HasNext)
            {
                // Call the API method which returns a PagedList<Transaction> result
                transactions.FetchNext()
                // Result if everything went well
                .Done(delegate(PagedList <Transaction> transactionsList)
                {
                    DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:TransactionFeatures] FetchNext success ›› {0} transaction(s)", transactionsList.Count));

                    // Call the OnSuccess action if any callback registered to it
                    if (OnSuccess != null)
                    {
                        OnSuccess(transactionsList);
                    }
                },
                      // Result if an error occured
                      delegate(Exception exception)
                {
                    // Call the OnError action if any callback registered to it
                    if (OnError != null)
                    {
                        OnError(ExceptionTools.GetExceptionError(exception));
                    }
                    // Else, log the error (expected to be a CotcException)
                    else
                    {
                        ExceptionTools.LogCotcException("TransactionFeatures", "FetchNext", exception);
                    }
                });
            }
            else
            {
                DebugLogs.LogError("[CotcSdkTemplate:TransactionFeatures] There is no next page");
            }
        }
        /// <summary>
        /// Post a new score on the given leaderboard for the current logged in gamer.
        /// </summary>
        /// <param name="scoreValue">Value of the score to set.</param>
        /// <param name="boardName">Name of the board to wich to set the score.</param>
        /// <param name="scoreOrder">Determines if the higher or the lower scores are the best ones.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="scoreDescription">Description of the score to set. (optional)</param>
        /// <param name="forceSave">If the score has to be saved even if it's not a better one. (optional)</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_Post(long scoreValue, string boardName, ScoreOrder scoreOrder, Action <PostedGameScore> OnSuccess = null, Action <ExceptionError> OnError = null, string scoreDescription = null, bool forceSave = false, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a PostedGameScore result
            LoginFeatures.gamer.Scores.Domain(domain).Post(scoreValue, boardName, scoreOrder, scoreDescription, forceSave)
            // Result if everything went well
            .Done(delegate(PostedGameScore postedScore)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:LeaderboardFeatures] Post success ›› Has Been Saved: {0}, Score Rank: {1}", postedScore.HasBeenSaved, postedScore.Rank));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(postedScore);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("LeaderboardFeatures", "Post", exception);
                }
            });
        }
Example #14
0
        /// <summary>
        /// Get the current logged in gamer currencies balance.
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_Balance(Action <Bundle> OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a Bundle result
            LoginFeatures.gamer.Transactions.Domain(domain).Balance()
            // Result if everything went well
            .Done(delegate(Bundle currentBalance)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:TransactionFeatures] Balance success ›› Current Balance: {0}", currentBalance));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(currentBalance);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("TransactionFeatures", "Balance", exception);
                }
            });
        }
        /// <summary>
        /// Get the current logged in gamer's best scores from all leaderboards in which he scored at least once.
        /// </summary>
        /// <param name="noScoreErrorMessage">Error message to display in case of no score to display.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_ListUserBestScores(string noScoreErrorMessage, Action <Dictionary <string, Score>, string> OnSuccess = null, Action <ExceptionError, string> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType), noScoreErrorMessage);
                return;
            }

            // Call the API method which returns a Dictionary<string, Score> result
            LoginFeatures.gamer.Scores.Domain(domain).ListUserBestScores()
            // Result if everything went well
            .Done(delegate(Dictionary <string, Score> scoresList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:LeaderboardFeatures] ListUserBestScores success ›› {0} score(s)", scoresList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(scoresList, noScoreErrorMessage);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception), noScoreErrorMessage);
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("LeaderboardFeatures", "ListUserBestScores", exception);
                }
            });
        }
        /// <summary>
        /// Get the previous page from the same board of a previously obtained leaderboard page.
        /// </summary>
        /// <param name="scores">Paged list of scores.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_FetchPrevious(PagedList <Score> scores, Action <PagedList <Score>, string> OnSuccess = null, Action <ExceptionError, string> OnError = null)
        {
            if (scores.HasPrevious)
            {
                // Call the API method which returns a PagedList<Score> result
                scores.FetchPrevious()
                // Result if everything went well
                .Done(delegate(PagedList <Score> scoresList)
                {
                    DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:LeaderboardFeatures] FetchPrevious success ›› {0} score(s)", scoresList.Count));

                    // Call the OnSuccess action if any callback registered to it
                    if (OnSuccess != null)
                    {
                        OnSuccess(scoresList, null);
                    }
                },
                      // Result if an error occured
                      delegate(Exception exception)
                {
                    // Call the OnError action if any callback registered to it
                    if (OnError != null)
                    {
                        OnError(ExceptionTools.GetExceptionError(exception), null);
                    }
                    // Else, log the error (expected to be a CotcException)
                    else
                    {
                        ExceptionTools.LogCotcException("LeaderboardFeatures", "FetchPrevious", exception);
                    }
                });
            }
            else
            {
                DebugLogs.LogError("[CotcSdkTemplate:LeaderboardFeatures] There is no previous page");
            }
        }
Example #17
0
        /// <summary>
        /// Get logged in gamer's progress on all game's achievements.
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_ListAchievements(Action <Dictionary <string, AchievementDefinition> > OnSuccess = null, Action <ExceptionError> OnError = null, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a Dictionary<string, AchievementDefinition> result
            LoginFeatures.gamer.Achievements.Domain(domain).List()
            // Result if everything went well
            .Done(delegate(Dictionary <string, AchievementDefinition> achievementsList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:AchievementFeatures] List success ›› {0} achievement(s)", achievementsList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(achievementsList);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("AchievementFeatures", "List", exception);
                }
            });
        }
Example #18
0
        /// <summary>
        /// Send an email to a gamer who has lost its email account's password.
        /// </summary>
        /// <param name="toEmailAddress">Email address of the gamer to who the email will be sent.</param>
        /// <param name="fromEmailAddress">Email address of the company from which the email will be sent.</param>
        /// <param name="emailTitle">Title of the email to send.</param>
        /// <param name="emailBody">Body of the email to send. (needs to contain the [[SHORTCODE]] tag)</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_SendResetPasswordEmail(string toEmailAddress, string fromEmailAddress, string emailTitle, string emailBody, Action <Done> OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Need an initialized Cloud to proceed
            if (!CloudFeatures.IsCloudInitialized())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotSetup), ExceptionTools.notInitializedCloudErrorType));
                return;
            }

            // Call the API method which returns a Done result
            CloudFeatures.cloud.SendResetPasswordEmail(toEmailAddress, fromEmailAddress, emailTitle, emailBody)
            // Result if everything went well
            .Done(delegate(Done sendDone)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:AccountFeatures] SendResetPasswordEmail success ›› Successful: {0}", sendDone.Successful));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(sendDone);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("AccountFeatures", "SendResetPasswordEmail", exception);
                }
            });
        }
Example #19
0
        /// <summary>
        /// Change a logged in gamer's email account's password.
        /// </summary>
        /// <param name="newPassword">New password of the gamer's email account.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_ChangePassword(string newPassword, Action <Done> OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(CotcSdk.ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a Done result
            LoginFeatures.gamer.Account.ChangePassword(newPassword)
            // Result if everything went well
            .Done(delegate(Done changeDone)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:AccountFeatures] ChangePassword success ›› Successful: {0}", changeDone.Successful));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(changeDone);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("AccountFeatures", "ChangePassword", exception);
                }
            });
        }
Example #20
0
        /// <summary>
        /// Get the list of current logged in gamer's friends (or blacklisted gamers).
        /// </summary>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        /// <param name="blacklisted">Get blacklisted gamers instead of friends. (optional)</param>
        /// <param name="domain">We use the "private" domain by default (each game holds its own data, not shared with the other games). You may configure shared domains on your FrontOffice.</param>
        public static void Backend_ListFriends(Action <NonpagedList <GamerInfo> > OnSuccess = null, Action <ExceptionError> OnError = null, bool blacklisted = false, string domain = "private")
        {
            // Need an initialized Cloud and a logged in gamer to proceed
            if (!LoginFeatures.IsGamerLoggedIn())
            {
                OnError(ExceptionTools.GetExceptionError(new CotcException(ErrorCode.NotLoggedIn), ExceptionTools.notLoggedInErrorType));
                return;
            }

            // Call the API method which returns a NonpagedList<GamerInfo> result
            LoginFeatures.gamer.Community.Domain(domain).ListFriends(blacklisted)
            // Result if everything went well
            .Done(delegate(NonpagedList <GamerInfo> friendsList)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:CommunityFeatures] ListFriends success ›› {0} friend(s) (or blacklisted)", friendsList.Count));

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(friendsList);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("CommunityFeatures", "ListFriends", exception);
                }
            });
        }
Example #21
0
 /// <summary>
 /// Log unhandled exceptions (when backend requests errors occur without any .Catch or .Then block set)
 /// </summary>
 /// <param name="sender">The exception sender object reference.</param>
 /// <param name="exceptionEventArgs">The exception event details.</param>
 private static void LogUnhandledException(object sender, ExceptionEventArgs exceptionEventArgs)
 {
     // The exception should always be of the CotcException type
     ExceptionTools.LogCotcException("CloudFeatures", "Unhandled", exceptionEventArgs.Exception);
 }