示例#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);
                }
            });
        }
示例#2
0
        /// <summary>
        /// Check if the CotcSdk's Cloud instance is initialized and a Gamer is logged in.
        /// </summary>
        /// <param name="verbose">If the check should log in case of error.</param>
        public static bool IsGamerLoggedIn(bool verbose = true)
        {
            if (!CloudFeatures.IsCloudInitialized(verbose))
            {
                return(false);
            }

            if (gamer == null)
            {
                if (verbose)
                {
                    DebugLogs.LogError("[CotcSdkTemplate:LoginFeatures] No Gamer is logged in ›› Please call a login method first (some of the CotcSdk features are not available otherwise)");
                }

                return(false);
            }

            return(true);
        }
示例#3
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);
                }
            });
        }
        /// <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);
                }
            });
        }
示例#5
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);
                }
            });
        }