From fc7992bab9284d03e86dacf7435aaaf29aa6cd29 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Tue, 26 Mar 2024 15:33:22 -0500 Subject: [PATCH 1/3] add session helper, WIP --- lib/Source/io/newgrounds/NG.hx | 291 +++-------- lib/Source/io/newgrounds/NGLite.hx | 4 +- .../io/newgrounds/components/AppComponent.hx | 12 +- lib/Source/io/newgrounds/swf/MedalPopup.hx | 2 +- .../io/newgrounds/utils/SaveSlotList.hx | 2 +- lib/Source/io/newgrounds/utils/SessionUtil.hx | 457 ++++++++++++++++++ .../io/newgrounds/test/ui/CloudSavePage.hx | 2 +- .../Source/io/newgrounds/test/ui/CorePage.hx | 4 +- .../Source/io/newgrounds/test/ui/Input.hx | 2 +- 9 files changed, 550 insertions(+), 226 deletions(-) create mode 100644 lib/Source/io/newgrounds/utils/SessionUtil.hx diff --git a/lib/Source/io/newgrounds/NG.hx b/lib/Source/io/newgrounds/NG.hx index 7260998..7aedaba 100644 --- a/lib/Source/io/newgrounds/NG.hx +++ b/lib/Source/io/newgrounds/NG.hx @@ -19,6 +19,7 @@ import io.newgrounds.utils.ExternalAppList; import io.newgrounds.utils.MedalList; import io.newgrounds.utils.SaveSlotList; import io.newgrounds.utils.ScoreBoardList; +import io.newgrounds.utils.SessionUtil; #if (openfl < "4.0.0") import openfl.utils.JNI; #elseif (lime) @@ -40,53 +41,88 @@ class NG extends NGLite { // --- DATA /** The logged in user */ + @:deprecated("user is deprecated, use session.current.user") public var user(get, never):User; function get_user():User { - if (_session == null) + final session = _session; + if (session == null) return null; - return _session.user; + return session.user; } + // Todo:deprecate public var passportUrl(get, never):String; function get_passportUrl():String { - if (_session == null || _session.status != SessionStatus.REQUEST_LOGIN) - return null; - - return _session.passportUrl; + return session.getPassportUrl(); } + + /** Helper for starting, ending and continuing sessions */ + public var session(default, null):SessionUtil; + + /** Helper for unlocking, and checking the unlock status of medals */ public var medals(default, null):MedalList; + + /** Helper for posting, and retrieving scoreboards and scores */ public var scoreBoards(default, null):ScoreBoardList; + + /** Helper for reading and writing to save slots */ public var saveSlots(default, null):SaveSlotList; + + /** A list of external apps about which you may access limited information */ public var externalApps(default, null):ExternalAppList; // --- EVENTS - public var onLogin(default, null):Dispatcher; - public var onLogOut(default, null):Dispatcher; + @:deprecated("Use NG.session.onLogIn") + public var onLogin(get, never):Dispatcher; + inline function get_onLogin() return session.onLogIn; + + @:deprecated("Use NG.session.onLogOut") + public var onLogOut(get, never):Dispatcher; + inline function get_onLogOut() return session.onLogOut; - @:deprecated("Use medals.onLoad") + @:deprecated("Use NG.medals.onLoad") public var onMedalsLoaded(get, never):Dispatcher; - inline function get_onMedalsLoaded() return medals.onLoad; + inline function get_onMedalsLoaded() return medals.onLoad; - @:deprecated("Use scoreBoards.onLoad") + @:deprecated("Use NG.scoreBoards.onLoad") public var onScoreBoardsLoaded(get, never):Dispatcher; - inline function get_onScoreBoardsLoaded() return scoreBoards.onLoad; + inline function get_onScoreBoardsLoaded() return scoreBoards.onLoad; - @:deprecated("Use saveSlots.onLoad") + @:deprecated("Use NG.saveSlots.onLoad") public var onSaveSlotsLoaded(get, never):Dispatcher; - inline function get_onSaveSlotsLoaded() return saveSlots.onLoad; + inline function get_onSaveSlotsLoaded() return saveSlots.onLoad; // --- MISC - public var loggedIn(default, null) = false; - public var attemptingLogin(default, null) = false; + @:deprecated("loggedIn is deprecated, use session.status") + public var loggedIn(get, never):Bool; + function get_loggedIn() { + + return session.status.match(LOGGED_IN(_)); + } - var _loginCancelled = false; - var _passportCallback:Void->Void; + @:deprecated("attemptingLogin is deprecated, use session.status") + public var attemptingLogin(get, never):Bool; + function get_attemptingLogin() { + + return switch (session.status) { + + case AWAITING_PASSPORT(_): true; + case STARTING_NEW : true; + case CHECKING_STATUS(_) : true; + case LOGGED_OUT : false; + case LOGGED_IN(_) : false; + } + } - var _session:Session; + var _session(get, never):Session; + function get__session() { + + return session.current; + } /** * Iniitializes the API, call before utilizing any other component @@ -102,17 +138,17 @@ class NG extends NGLite { ) { host = getHost(); - onLogin = new Dispatcher(); - onLogOut = new Dispatcher(); + session = new SessionUtil(this); medals = new MedalList(this); saveSlots = new SaveSlotList(this); scoreBoards = new ScoreBoardList(this); externalApps = new ExternalAppList(this); - attemptingLogin = sessionId != null; + super(appId, null, debug); - super(appId, sessionId, debug, callback); + // if (sessionId != null) + // session.connectTo() } /** @@ -145,28 +181,17 @@ class NG extends NGLite { , ?callback:(LoginOutcome)->Void ):Void { - var session = NGLite.getSessionId(); - if (session == null) - session = backupSession; + var sessionId = NGLite.getSessionId(); + if (sessionId == null) + sessionId = backupSession; - create(appId, session, debug, callback); - - if (core.sessionId != null) - core.attemptingLogin = true; + create(appId, sessionId, debug, callback); } // ------------------------------------------------------------------------------------------- // APP // ------------------------------------------------------------------------------------------- - override function checkInitialSession - ( callback:Null<(LoginOutcome)->Void> - , outcome:CallOutcome - ):Void { - - onSessionReceive(outcome, callback, null); - } - /** * Begins the login process * @@ -177,64 +202,13 @@ class NG extends NGLite { * must open links on click events or else it will be blocked by the * popup blocker. */ - public function requestLogin + @:deprecated("requestLogin is deprecated, use session.startNew, instead") + inline public function requestLogin ( callback:(LoginOutcome)->Void = null , passportHandler:String->Void = null ):Void { - if (attemptingLogin) { - - throw "cannot request another login until the previous attempt is complete"; - } - - if (loggedIn) { - - logError("cannot log in, already logged in"); - callback.safe(SUCCESS); - return; - } - - attemptingLogin = true; - _loginCancelled = false; - _passportCallback = null; - - calls.app.startSession(true) - .addOutcomeHandler(onSessionReceive.bind(_, callback, passportHandler)) - .send(); - } - - function onSessionReceive - ( outcome:CallOutcome - , callback:Null<(LoginOutcome)->Void> - , passportHandler:String->Void - ):Void { - - switch(outcome) - { - case SUCCESS(data): _session = data.session; - case FAIL(error): - - sessionId = null; - endLogin(); - - callback.safe(FAIL(ERROR(error))); - return; - } - - sessionId = _session.id; - - logVerbose('session started - status: ${_session.status}'); - - if (_session.status == REQUEST_LOGIN) { - - _passportCallback = checkSessionStatus.bind(callback); - if (passportHandler != null) - passportHandler(passportUrl); - else - openPassportUrl(); - - } else - checkSessionStatus(callback); + session.startNew(callback, passportHandler); } /** @@ -243,17 +217,10 @@ class NG extends NGLite { */ public function openPassportUrl():Void { - if (passportUrl != null) { - - logVerbose('loading passport: ${passportUrl}'); - openPassportHelper(passportUrl); - dispatchPassportCallback(); - - } else - logError("Cannot open passport"); + session.openPassportUrl(); } - function openPassportHelper(url:String):Void { + function openUrl(url:String):Void { var window = "_blank"; #if flash @@ -275,7 +242,7 @@ class NG extends NGLite { case name: logError("Unhandled systemName: " + name); } #else - logError("Could not open passport url, unhandled target"); + logError('Could not open url: $url, unhandled target'); #end } @@ -284,127 +251,19 @@ class NG extends NGLite { */ public function onPassportUrlOpen():Void { - dispatchPassportCallback(); - } - - function dispatchPassportCallback():Void { - - if (_passportCallback != null) { - - logVerbose("dispatching passport callback"); - var callback = _passportCallback; - _passportCallback = null; - callback(); - } - } - - function checkSession(outcome:CallOutcome, callback:Null<(LoginOutcome)->Void>) { - - switch (outcome) { - - case FAIL(_): - log("login cancelled via passport"); - - endLoginAndCall(callback, FAIL(CANCELLED(PASSPORT))); - - case SUCCESS(data): - - logVerbose("Session received"); - - _session = data.session; - checkSessionStatus(callback); - } - } - - function checkSessionStatus(callback:Null<(LoginOutcome)->Void>) { - - if (_loginCancelled) - { - log("login cancelled via cancelLoginRequest"); - - endLoginAndCall(callback, FAIL(CANCELLED(MANUAL))); - return; - } - - switch(_session.status) { - - case USER_LOADED: - - loggedIn = true; - endLoginAndCall(callback, SUCCESS); - onLogin.dispatch(); - - case REQUEST_LOGIN: - - var call = calls.app.checkSession() - .addOutcomeHandler(checkSession.bind(_, callback)); - - // Wait 3 seconds and try again - timer(3.0, - function():Void { - - logVerbose("3s elapsed, checking session again"); - - // Check if cancelLoginRequest was called - if (!_loginCancelled) - call.send(); - else { - - log("login cancelled via cancelLoginRequest"); - endLoginAndCall(callback, FAIL(CANCELLED(MANUAL))); - } - } - ); - - case SESSION_EXPIRED: - - log("login cancelled via passport"); - - // The user cancelled the passport - endLoginAndCall(callback, FAIL(CANCELLED(PASSPORT))); - } + // no longer needed } + @:deprecated('cancelLoginRequest') public function cancelLoginRequest():Void { - if (attemptingLogin) - { - _loginCancelled = true; - // Pretend we opened the passport to process the client cancel. - dispatchPassportCallback(); - } - } - - function endLogin():Void { - - attemptingLogin = false; - _loginCancelled = false; - } - - function endLoginAndCall(callback:Null<(LoginOutcome)->Void>, outcome:LoginOutcome) { - - endLogin(); - - callback.safe(outcome); - } - - public function logOut(onComplete:(Outcome)->Void = null) { - - var call = calls.app.endSession() - .addSuccessHandler(onLogOutSuccessful); - - if (onComplete != null) - call.addOutcomeHandler((o)->onComplete(o.toUntyped())); - - call.addSuccessHandler(onLogOut.dispatch) - .send(); + if (session.status.match(AWAITING_PASSPORT(_) | STARTING_NEW)) + session.cancel(); } - function onLogOutSuccessful():Void { + public function logOut(?onComplete:(Outcome)->Void) { - _session = null; - sessionId = null; - loggedIn = false; + session.endCurrent(onComplete); } /** diff --git a/lib/Source/io/newgrounds/NGLite.hx b/lib/Source/io/newgrounds/NGLite.hx index d1db414..6c1a8e6 100644 --- a/lib/Source/io/newgrounds/NGLite.hx +++ b/lib/Source/io/newgrounds/NGLite.hx @@ -154,7 +154,7 @@ class NGLite { create(appId, session, callback); } - inline static public function getUrl():String { + inline static public function getUrl():Null { #if js return js.Browser.document.location.href; @@ -167,7 +167,7 @@ class NGLite { #end } - static public function getSessionId():String { + static public function getSessionId():Null { #if js diff --git a/lib/Source/io/newgrounds/components/AppComponent.hx b/lib/Source/io/newgrounds/components/AppComponent.hx index d23fe1e..e552754 100644 --- a/lib/Source/io/newgrounds/components/AppComponent.hx +++ b/lib/Source/io/newgrounds/components/AppComponent.hx @@ -13,9 +13,17 @@ class AppComponent extends Component { .addComponentParameter("force", force, false); } - public function checkSession():Call { + /** + * Checks the status of the supplied session id + * @param id If null, the current session is used + */ + public function checkSession(?id:String):Call { - return new Call(_core, "App.checkSession", true); + return if (id == null) + new Call(_core, "App.checkSession", true); + else + new Call(_core, "App.checkSession", false) + .addProperty("session_id", id); } public function endSession():Call { diff --git a/lib/Source/io/newgrounds/swf/MedalPopup.hx b/lib/Source/io/newgrounds/swf/MedalPopup.hx index 93e80e3..7d0dd88 100644 --- a/lib/Source/io/newgrounds/swf/MedalPopup.hx +++ b/lib/Source/io/newgrounds/swf/MedalPopup.hx @@ -55,7 +55,7 @@ class MedalPopup extends BaseAsset { onMedalsLoaded(); else { - NG.core.onLogin.addOnce(function () { + NG.core.session.onLogIn.addOnce(function () { NG.core.medals.onLoad.addOnce(onMedalsLoaded); NG.core.medals.loadList(); diff --git a/lib/Source/io/newgrounds/utils/SaveSlotList.hx b/lib/Source/io/newgrounds/utils/SaveSlotList.hx index 967eade..cdce6ab 100644 --- a/lib/Source/io/newgrounds/utils/SaveSlotList.hx +++ b/lib/Source/io/newgrounds/utils/SaveSlotList.hx @@ -54,7 +54,7 @@ private class RawSaveSlotList extends ObjectList { */ public function loadList(?callback:(Outcome)->Void) { - if (_core.loggedIn == false) + if (_core.session.status.match(LOGGED_IN(_)) == false) throw "Must be logged in to request cloud saves"; if (checkState(callback) == false) diff --git a/lib/Source/io/newgrounds/utils/SessionUtil.hx b/lib/Source/io/newgrounds/utils/SessionUtil.hx new file mode 100644 index 0000000..8a0f58c --- /dev/null +++ b/lib/Source/io/newgrounds/utils/SessionUtil.hx @@ -0,0 +1,457 @@ +package io.newgrounds.utils; + +import io.newgrounds.Call; +import io.newgrounds.NG; +import io.newgrounds.NGLite; +import io.newgrounds.objects.Session; +import io.newgrounds.objects.events.Outcome; +import io.newgrounds.objects.events.Result; + +/** + * + * @author GeoKureli + */ +@:allow(io.newgrounds.NG) +@:access(io.newgrounds.NG) +class SessionUtil { + + /** The session id found in url params */ + public final initialId:Null; + + /** Called whenever the api connects to an active session */ + public final onLogIn:Dispatcher; + /** Called whenever the api disconnects from the active session */ + public final onLogOut:Dispatcher; + + /** The session status of the api */ + public var status:LoginStatus = LOGGED_OUT; + + /** The current active session, if logged in */ + public var current(get, never):Session; + inline function get_current():Session { + + return switch(status) { + + case LOGGED_IN(session): session; + default: null; + } + } + + final _core:NG; + + public function new(core:NG) { + + _core = core; + initialId = NGLite.getSessionId(); + onLogIn = new Dispatcher(); + onLogOut = new Dispatcher(); + } + + /** + * Tries to login any way it can. It first tries to connect to the `initialId` if any, if + * there is no initial session or if it is expires it will start a new session. + * + * @param callback Receives the result of the login attempt + * @param passportHandler Called once the passport url is known, if `null`, the url is opened + * automatically. **Note:** some browsers have restrictions where + * urls must be opened via user input, such as a mouse click or + * keyboard event. + */ + public function autoConnect(callback:(LoginOutcome)->Void, ?passportHandler:(String)->Void) { + + if (initialId != null) { + + function onConnectOutcome (outcome:SessionCheckOutcome) { + + switch outcome { + + case SUCCESS(_): callback(SUCCESS); + case FAIL(CALL(error)): callback(FAIL(ERROR(error))); + case FAIL(CANCELLED(type)): callback(FAIL(CANCELLED(type))); + case FAIL(EXPIRED): + startNew(callback, passportHandler); + } + } + + connectTo(initialId, onConnectOutcome, passportHandler); + + } else { + + startNew(callback, passportHandler); + } + } + + /** + * Checks the status of the supplied session id, if the session is active, it will connect + * + * @param sessionId The id of session to connect to + * @param callback Receives the result of the login attempt + * @param passportHandler Called once the passport url is known, if `null`, the url is opened + * automatically. **Note:** some browsers have restrictions where + * urls must be opened via user input, such as a mouse click or + * keyboard event. + */ + public function connectTo(sessionId:String, callback:(SessionCheckOutcome)->Void, ?passportHandler:(String)->Void) { + + switch (status) { + + case LOGGED_IN(_): + throw 'Cannot check session id while in another session. Log out, first'; + case AWAITING_PASSPORT(_): + throw 'Cannot check session id while attemping to start a new session. Cancel the current passport, first'; + case STARTING_NEW: + throw 'Cannot check session id while attemping to start a new session. Cancel login, first'; + case CHECKING_STATUS(oldId) if (oldId == sessionId): + throw 'Already checking session: $oldId, wait before checking again'; + case CHECKING_STATUS(oldId): + throw 'Already checking session: $oldId, wait before checking new session: $sessionId'; + case LOGGED_OUT: + // no problemo + } + + status = CHECKING_STATUS(sessionId); + + _core.calls.app.checkSession(sessionId) + .addOutcomeHandler((outcome)->{ + + // check if cancelled + if (isCheckingStatus(sessionId) == false) + { + callback(FAIL(CANCELLED(MANUAL))); + return; + } + + onSessionCheckOutcome(outcome, callback, passportHandler); + }) + .send(); + } + + function isCheckingStatus(sessionId:String) { + + return switch status { + + case CHECKING_STATUS(id) if (id == sessionId): true; + default: false; + } + } + + function isAwaitingPassport(session:Session) { + + return switch status { + + case AWAITING_PASSPORT(s) if (s.id == session.id): true; + default: false; + } + } + + function onSessionCheckOutcome(outcome:CallOutcome, callback:(SessionCheckOutcome)->Void, ?passportHandler:(String)->Void) + { + switch outcome { + + case SUCCESS(data): + + switch (data.session.status) { + + case SESSION_EXPIRED: + + status = LOGGED_OUT; + callback(FAIL(EXPIRED)); + + case REQUEST_LOGIN: + + handlePassport(data.session, passportHandler, (outcome)->switch outcome { + case SUCCESS(session): + + onSessionConnect(session); + callback(SUCCESS(session)); + + case FAIL(error): + + status = LOGGED_OUT; + callback(FAIL(error)); + }); + + case USER_LOADED: + + onSessionConnect(data.session); + callback(SUCCESS(data.session)); + } + + case FAIL(error): + + status = LOGGED_OUT; + callback(FAIL(CALL(error))); + } + } + + function onSessionConnect(session:Session) { + + status = LOGGED_IN(session); + onLogIn.dispatch(); + } + + function handlePassport(session:Session, ?handler:(String)->Void, callback:(SessionCheckOutcome)->Void) { + + status = AWAITING_PASSPORT(session); + if (handler != null) + handler(session.passportUrl); + else + _core.openUrl(session.passportUrl); + + waitForPassport(session, callback); + } + + function waitForPassport(session:Session, callback:(SessionCheckOutcome)->Void) { + + timer(1.0, ()->{ + // check if cancelled + final status = status; + if (isAwaitingPassport(session) == false) { + + callback(FAIL(CANCELLED(MANUAL))); + return; + } + + _core.calls.app.checkSession(session.id) + .addOutcomeHandler((outcome)->{ + + // check if cancelled, again + if (isAwaitingPassport(session) == false) { + + callback(FAIL(CANCELLED(MANUAL))); + return; + } + + switch (outcome) { + + case SUCCESS(data): + + switch data.session.status { + + case SESSION_EXPIRED: callback(FAIL(CANCELLED(PASSPORT))); + case REQUEST_LOGIN: waitForPassport(data.session, callback); + case USER_LOADED: callback(SUCCESS(data.session)); + } + + case FAIL(error): + callback(FAIL(CALL(error))); + } + // waitForPassport(session, callback); + }) + .send(); + } + ); + } + + function timer(delay:Float, callback:()->Void):Void { + + var timer = new haxe.Timer(Std.int(delay * 1000)); + timer.run = function func():Void { + + timer.stop(); + callback(); + } + } + + /** + * Starts a new session + * + * @param callback Receives the result of the login attempt + * @param passportHandler Called once the passport url is known, if `null`, the url is opened + * automatically. **Note:** some browsers have restrictions where + * urls must be opened via user input, such as a mouse click or + * keyboard event. + */ + public function startNew(callback:(LoginOutcome)->Void, ?passportHandler:(String)->Void) { + + switch (status) { + + case LOGGED_IN(_): + throw 'Cannot log in while already logged in. Log out, first'; + case AWAITING_PASSPORT(_) + | STARTING_NEW: + throw 'Cannot log in while already attemping to start a new session. Cancel login, first'; + case CHECKING_STATUS(_): + throw 'Cannot log in while checking a session status. Cancel, first'; + case LOGGED_OUT: + // no problemo + } + + status = STARTING_NEW; + _core.calls.app.startSession(true) + .addOutcomeHandler( + function (outcome) { + + // check if cancelled + if (status.match(STARTING_NEW) == false) { + + callback(FAIL(CANCELLED(MANUAL))); + return; + } + + final session = switch(outcome) { + + case SUCCESS(data): data.session; + case FAIL(error): + + status = LOGGED_OUT; + callback(FAIL(ERROR(error))); + return; + } + + _core.logVerbose('session started - status: ${session.status}'); + + switch (session.status) { + + case SESSION_EXPIRED: + + status = LOGGED_OUT; + callback(FAIL(CANCELLED(PASSPORT))); + + case USER_LOADED://should never happen, but ok lol + + onSessionConnect(session); + callback(SUCCESS); + + case REQUEST_LOGIN: + + handlePassport(session, passportHandler, (outcome:SessionCheckOutcome)->switch outcome { + + case SUCCESS(connectedSession): + + onSessionConnect(connectedSession); + callback(SUCCESS); + + case FAIL(CANCELLED(type)): + + status = LOGGED_OUT; + callback(FAIL(CANCELLED(type))); + + case FAIL(EXPIRED): + + status = LOGGED_OUT; + callback(FAIL(CANCELLED(PASSPORT))); + + case FAIL(CALL(error)): + + status = LOGGED_OUT; + callback(FAIL(ERROR(error))); + }); + } + } + ) + .send(); + } + + /** + * Logs out of the current session + * + * @param onComplete Receives the result of the end session call + */ + public function endCurrent(?onComplete:(Outcome)->Void) { + + switch (status) { + + case LOGGED_IN(_): // all good + case CHECKING_STATUS(sessionId): + throw 'Cannot end the current session until the session status is determinined. Cancel, first.'; + case LOGGED_OUT: + throw 'Cannot end the current session if there is no session.'; + case STARTING_NEW: + cancel(); + case AWAITING_PASSPORT(_): + cancel(); + } + + function onSuccess() { + + status = LOGGED_OUT; + onLogOut.dispatch(); + }; + + var call = _core.calls.app.endSession() + .addSuccessHandler(onSuccess); + + if (onComplete != null) { + + call.addOutcomeHandler((outcome)->switch outcome { + + case SUCCESS(_): onComplete(SUCCESS); + case FAIL(error): onComplete(FAIL(error)); + }); + } + + call.send(); + } + + /** + * Cancels any current attempt to log in. Does not log out, if you're logged in + */ + public function cancel() { + + switch (status) { + + case CHECKING_STATUS(_) + | STARTING_NEW + | AWAITING_PASSPORT(_): + + case LOGGED_OUT: + _core.logError('Attempting to cancel login when already logged out'); + case LOGGED_IN(_): + _core.logError('To end the current session use endCurrent(), not cancel()'); + } + + status = LOGGED_OUT; + } + + /** + * Cancelled any current attempt to log in. Does not log out, if you're logged in + */ + function getPassportUrl() { + + return switch (status) { + + case AWAITING_PASSPORT(session): session.passportUrl; + case LOGGED_IN(session): session.passportUrl; + default: null; + } + } + + /** + * Cancelled any current attempt to log in. Does not log out, if you're logged in + */ + public function openPassportUrl() { + + switch (status) { + + case AWAITING_PASSPORT(session): + + _core.openUrl(session.passportUrl); + + case LOGGED_IN(_): + throw 'Cannot open the passport url when already logged in'; + case LOGGED_OUT: + throw 'Cannot open the passport url while logged out'; + default: + throw 'Cannot open the passport url'; + } + } +} + +enum LoginStatus { + + LOGGED_OUT; + CHECKING_STATUS(sessionId:String); + STARTING_NEW; + AWAITING_PASSPORT(session:Session); + LOGGED_IN(session:Session); +} + +enum CheckSessionError +{ + CALL(error:CallError); + CANCELLED(type:LoginCancel); + EXPIRED; +} + +typedef SessionCheckOutcome = TypedOutcome; \ No newline at end of file diff --git a/test/openfl-swf/Source/io/newgrounds/test/ui/CloudSavePage.hx b/test/openfl-swf/Source/io/newgrounds/test/ui/CloudSavePage.hx index d7d2c18..517d05f 100644 --- a/test/openfl-swf/Source/io/newgrounds/test/ui/CloudSavePage.hx +++ b/test/openfl-swf/Source/io/newgrounds/test/ui/CloudSavePage.hx @@ -56,7 +56,7 @@ class CloudSavePage extends Page { case Empty if (NG.core.loggedIn == false): setMessage("Login to get save slots"); - NG.core.onLogin.addOnce(function () { + NG.core.session.onLogIn.addOnce(function () { if (NG.core.saveSlots.state != Loaded) setMessage("Loading..."); diff --git a/test/openfl-swf/Source/io/newgrounds/test/ui/CorePage.hx b/test/openfl-swf/Source/io/newgrounds/test/ui/CorePage.hx index d187623..e1496f9 100644 --- a/test/openfl-swf/Source/io/newgrounds/test/ui/CorePage.hx +++ b/test/openfl-swf/Source/io/newgrounds/test/ui/CorePage.hx @@ -58,8 +58,8 @@ class CorePage extends CorePageLite { _openPassport.enabled = false; _profileButton.onClick = onProfileClick; - NG.core.onLogin.add(onLogin); - NG.core.onLogOut.add(onLogOut); + NG.core.session.onLogIn.add(onLogin); + NG.core.session.onLogOut.add(onLogOut); if (NG.core.attemptingLogin) { diff --git a/test/openfl-swf/Source/io/newgrounds/test/ui/Input.hx b/test/openfl-swf/Source/io/newgrounds/test/ui/Input.hx index 5a12ba6..cd24f2e 100644 --- a/test/openfl-swf/Source/io/newgrounds/test/ui/Input.hx +++ b/test/openfl-swf/Source/io/newgrounds/test/ui/Input.hx @@ -99,7 +99,7 @@ class Input { while(i < parent.numChildren) { child = parent.getChildAt(i); - if (Std.is(child, TextField)) { + if (Std.isOfType(child, TextField)) { field = cast (child, TextField); if (field.background) { From 272cce5dbc059bce9e900490a610330ff36db20c Mon Sep 17 00:00:00 2001 From: George FunBook Date: Tue, 26 Mar 2024 15:42:34 -0500 Subject: [PATCH 2/3] fix legacy login stuff --- lib/Source/io/newgrounds/NG.hx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Source/io/newgrounds/NG.hx b/lib/Source/io/newgrounds/NG.hx index 7aedaba..ed8cc0d 100644 --- a/lib/Source/io/newgrounds/NG.hx +++ b/lib/Source/io/newgrounds/NG.hx @@ -147,8 +147,19 @@ class NG extends NGLite { super(appId, null, debug); - // if (sessionId != null) - // session.connectTo() + if (sessionId != null) { + + session.connectTo(sessionId, (outcome)->{ + + callback(switch (outcome) { + + case SUCCESS(_) : SUCCESS; + case FAIL(EXPIRED) : FAIL(CANCELLED(PASSPORT)); + case FAIL(CALL(error)) : FAIL(ERROR(error)); + case FAIL(CANCELLED(type)): FAIL(CANCELLED(type)); + }); + }); + } } /** From 6ddb7514bcfebb0f913dc99198a576cb3f4de09a Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 3 May 2024 16:27:40 -0400 Subject: [PATCH 3/3] add release --- release.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 release.sh diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..94df36f --- /dev/null +++ b/release.sh @@ -0,0 +1,2 @@ +# Same as release.bat but for unix +7z a -tzip -i!LICENSE.md -i!README.md -i!haxelib.json -i!lib newgrounds.zip