/// <summary> /// If a non-expired session has been loaded, this will open Newgrounds Passport in a browser window so the player may log in securely. /// At the time this class as written, Unity lacked the ability to open URLs in new tabs when built for WebGL /// When this is called from WebGL, a prompt will be drawn over your game asking the player if they want to sign in. /// This is necessary to load passport in conjunction with a mouse click so popup blockers can be bypassed. /// </summary> /// <returns></returns> public bool loadPassport() { SessionResult sr = new SessionResult(); sr.session = session; if (sr.getStatus() != SessionResult.REQUEST_LOGIN) { return(false); } if (ngioPluginLoaded()) { newgroundsioOpenPassportPrompt(session.passport_url); return(true); } else { Application.OpenURL(session.passport_url); return(true); } }
/// <summary> /// Will check the current status of a session. /// </summary> /// <param name="callback"></param> public void checkSession(Action <SessionResult> callback = null) { SessionResult sr = new SessionResult(); sr.session = session; Action <ResultModel> resultHandler = (ResultModel r) => { sr = (SessionResult)r; if (!r.success) { if (sr.error == null) { sr.error = new error { message = "Could not connect to Newgrounds.io server" } } ; if (sr.session == null) { sr.session = new session(); } } session = sr.session; if (callback != null) { callback(sr); } }; bool cooled = false; /* this makes sure we aren't spamming the newgrounds.io server (wich would get us blocked) */ if (first_check || stopwatch.ElapsedMilliseconds > 3000) { stopwatch.Reset(); stopwatch.Start(); cooled = true; first_check = false; } /* if we have an active session and our stopwatch has cooled down, reload the session from the server */ if (cooled && sr.getStatus() != SessionResult.SESSION_EXPIRED) { if (ngioPluginLoaded() && newgroundsioUserCancelledPrompt()) { SessionResult csr = new SessionResult(); csr.setIsLocal(true); session ns = new session(); ns.expired = true; ns.id = session.id; csr.session = ns; csr.success = false; csr.error.message = "User cancelled login"; if (callback != null) { callback(csr); } session = new session(); } else { _core.callComponent( "App.checkSession", null, resultHandler ); } } /* otherwise, just use the currently loaded session */ else { if (callback != null) { callback(sr); } } }