Ejemplo n.º 1
0
 /// <summary>
 /// Initializes your core instance
 /// </summary>
 /// <param name="app_id">The unique ID of your app as found in the 'API Tools' tab of your Newgrounds.com project.</param>
 /// <param name="aes_base64_key">Your 128-bit AES encryption key, encoded as a base64 string. This can be found in the 'API Tools' tab of your Newgrounds.com project.</param>
 /// <param name="session_id">If you have a saved session_id, you may set it here ahead of time.</param>
 public void initialize(string app_id, string aes_base64_key, string session_id = null)
 {
     this.app_id = app_id;
     this.crypto = new ngCrypto(aes_base64_key, ngCrypto.CIPHER_AES128, ngCrypto.ENCODE_BASE64);
     if (!string.IsNullOrEmpty(session_id))
     {
         this.session_id = session_id;
     }
     this.sessionLoader = new SessionLoader(this);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This will request a user's login status.  If the user is not logged in, Newgrounds Passport will be loaded in a new browser.
        /// Note: Due to security sandbox settings, WebGL players will see a prompt asking them if they want to load passport.
        /// </summary>
        public void requestLogin(Action onLoggedIn = null, Action onLoginFailed = null, Action onLoginCancelled = null)
        {
            SessionLoader sl = getSessionLoader();

            _waiting_for_login = false;

            // first, check any existing sessions we may have saved
            sl.checkSession((SessionResult r1) => {
                if (onLoggedIn != null)
                {
                    this.onLoggedIn(onLoggedIn);
                }
                if (onLoginFailed != null)
                {
                    this.onLoginFailed(onLoginFailed);
                }
                if (onLoginCancelled != null)
                {
                    this.onLoginCancelled(onLoginCancelled);
                }

                if (r1.getStatus() == SessionResult.USER_LOADED)
                {
                    // if we get here, the user has a valid, saved session
                    _loginSuccess(r1);
                }
                else
                {
                    // if we get here we need to start a new session
                    sl.startSession((SessionResult r2) =>
                    {
                        // this shouldn't ever happen unless there's a server issue.
                        if (r2.getStatus() == SessionResult.SESSION_EXPIRED)
                        {
                            _loginFailed(r2);
                        }

                        // if the user is already considered logged in, we're good to go
                        else if (r2.getStatus() == SessionResult.USER_LOADED)
                        {
                            _loginSuccess(r2);
                        }

                        // make a note that we are waiting for the user to log in now (see Update() method)
                        else
                        {
                            sl.loadPassport();
                            _waiting_for_login = true;
                        }
                    });
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks any current login status.
        /// </summary>
        /// <param name="callback">An optional callback. Will be sent a true/false value indicating the user's login status.</param>
        /// <param name="silent">If true, callbacks set via onLoggedIn, onLoginFailed and onLoginCancelled will not be executed.</param>
        public void checkLogin(Action <bool> callback = null)
        {
            SessionLoader sl = getSessionLoader();

            sl.checkSession((SessionResult r) => {
                bool logged_in = (r.getStatus() == SessionResult.USER_LOADED) ? true : false;
                if (callback != null)
                {
                    callback(logged_in);
                }
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Used to open URLs.
 /// </summary>
 /// <param name="url">The URL to open.</param>
 /// <param name="open_in_new_tab">Setto true if you want to URL opened in a new tab. WebGL games will prompt the user before doing so (to get around popup blockers).</param>
 public static void openUrl(string url, bool open_in_new_tab = false)
 {
     // if a new tab is requested and we're in WebGL mode, we need to use our plugin magic
     if (open_in_new_tab && SessionLoader.ngioPluginLoaded())
     {
         Application.ExternalCall("newgroundsio_plugin_openURL", url, "_blank");
     }
     else
     {
         Application.OpenURL(url);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Used to open URLs.
 /// </summary>
 /// <param name="url">The URL to open.</param>
 /// <param name="open_in_new_tab">Setto true if you want to URL opened in a new tab. WebGL games will prompt the user before doing so (to get around popup blockers).</param>
 public static void openUrl(string url, bool open_in_new_tab = false)
 {
     // if a new tab is requested and we're in WebGL mode, we need to use our plugin magic
     if (open_in_new_tab && SessionLoader.ngioPluginLoaded())
     {
         newgroundsioOpenUrlInNewTab(url);
     }
     else
     {
         Application.OpenURL(url);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Starts the monobehavior and fires the onReady callback (if available).
        /// </summary>
        void Start()
        {
            this.sessionLoader = new SessionLoader(this);
            if (!String.IsNullOrEmpty(app_id))
            {
                initialize(app_id, aes_base64_key, session_id);
            }

            _ready = true;
            if (_onready != null)
            {
                _onready();
            }
            _onready = null;
        }