From 9acfbf8484f38550af77d31d94f06abacc2fef06 Mon Sep 17 00:00:00 2001 From: Nick Leeman Date: Wed, 24 Feb 2021 00:44:03 +0100 Subject: [PATCH] added api, cleaned up status events --- siwg/api/siwg.api | 199 ++++++++++++++++++ siwg/src/java/com/aterve/siwg/SiwgJNI.java | 2 - siwg/src/siwg.cpp | 3 +- siwg/src/siwg.h | 1 - siwg/src/siwg_callback.cpp | 2 +- ...rivate_siwg_callback.h => siwg_callback.h} | 0 6 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 siwg/api/siwg.api rename siwg/src/{private_siwg_callback.h => siwg_callback.h} (100%) diff --git a/siwg/api/siwg.api b/siwg/api/siwg.api new file mode 100644 index 0000000..2132a6f --- /dev/null +++ b/siwg/api/siwg.api @@ -0,0 +1,199 @@ +- name: siwg + type: table + desc: Functions and constants for interacting with Google Services (SIWG) APIs + + members: + +#***************************************************************************************************** + + - name: is_supported + type: function + desc: Check if Google Services are available & ready on the device. + + returns: + - name: is_supported + type: boolean + desc: Status of Google Services on the device. + + examples: + - desc: |- + ```lua + if siwg then + local is_supported = siwg.is_supported() + end + ``` + +#***************************************************************************************************** + + - name: login + type: function + desc: Login to SIWG using a button. + + examples: + - desc: |- + Log in to SIWG using a button: + ```lua + if siwg then + siwg.login() + end + ``` + +#***************************************************************************************************** + + - name: silent_login + type: function + desc: Silent login to SIWG. + + This function is trying to retrieve the currently signed-in player’s account. + + [icon:attention] By default login methods request `GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN`. + But if you use Disk, we have to request extra scope `Drive.SCOPE_APPFOLDER`. + Or if you use ID token, we have to request ID token with provided client_id. + If so it causes the first time silent sign-in to fail, except for users who + have already signed in successfully on a different device. Turn off SIWG + features you don't want to use in `game.project`. + + examples: + - desc: |- + ```lua + function init(self) + if siwg then + siwg.silent_login() + end + end + ``` + +#***************************************************************************************************** + + - name: logout + type: function + desc: Logout from SIWG + + examples: + - desc: |- + ```lua + if siwg then + siwg.logout() + end + ``` + +#***************************************************************************************************** + + - name: get_display_name + type: function + desc: Get the current SIWG player display name. + + returns: + - name: name + type: string + desc: The player's display name. + + examples: + - desc: |- + ```lua + if siwg then + local name = siwg.get_display_name() + end + ``` + +#***************************************************************************************************** + + - name: get_id + type: function + desc: Get the current SIWG player id. + + returns: + - name: id + type: string + desc: The player ID. + + examples: + - desc: |- + ```lua + if siwg then + local id = siwg.get_id() + end + ``` + +#***************************************************************************************************** + + - name: get_id_token + type: function + desc: Get the current SIWG player id token. Available only if "siwg.client_id" is configured in game.project + and "siwg.request_id_token = 1". + + returns: + - name: id_token + type: string + desc: The player ID token. + + examples: + - desc: |- + ```lua + if siwg then + local id_token = siwg.get_id_token() + end + ``` + +#***************************************************************************************************** + + - name: get_server_auth_code + type: function + desc: Returns a one-time server auth code to send to your web server which can be exchanged for access token + + returns: + - name: server_auth_code + type: string + desc: The server auth code for logged in account. + + examples: + - desc: |- + ```lua + if siwg then + local server_auth_code = siwg.get_server_auth_code() + end + ``` + +#***************************************************************************************************** + + - name: is_logged_in + type: function + desc: Check if a user is logged in currently. + + returns: + - name: is_loggedin + type: boolean + desc: Current login state. + + examples: + - desc: |- + ```lua + if siwg then + local is_loggedin = siwg.is_logged_in() + end + ``` + +#***************************************************************************************************** + + - name: MSG_SIGN_IN + type: number + desc: The message type that SIWG sends when finishing the asynchronous operation + after calling `siwg.login()` + + - name: MSG_SILENT_SIGN_IN + type: number + desc: The message type that SIWG sends when finishing the asynchronous operation + after calling `siwg.silent_login()` + + - name: MSG_SIGN_OUT + type: number + desc: The message type that SIWG sends when finishing the asynchronous operation + after calling `siwg.logout()` + + - name: STATUS_SUCCESS + type: number + desc: An operation success. + + - name: STATUS_FAILED + type: number + desc: An operation failed. Check the error field in the massage table. \ No newline at end of file diff --git a/siwg/src/java/com/aterve/siwg/SiwgJNI.java b/siwg/src/java/com/aterve/siwg/SiwgJNI.java index fd09065..2a620d6 100644 --- a/siwg/src/java/com/aterve/siwg/SiwgJNI.java +++ b/siwg/src/java/com/aterve/siwg/SiwgJNI.java @@ -44,11 +44,9 @@ public class SiwgJNI { private static final int MSG_SIGN_IN = 1; private static final int MSG_SILENT_SIGN_IN = 2; private static final int MSG_SIGN_OUT = 3; - private static final int MSG_GET_EVENTS = 11; private static final int STATUS_SUCCESS = 1; private static final int STATUS_FAILED = 2; - private static final int STATUS_CONFLICT = 4; // // Global Properties diff --git a/siwg/src/siwg.cpp b/siwg/src/siwg.cpp index 8075336..48e9eee 100644 --- a/siwg/src/siwg.cpp +++ b/siwg/src/siwg.cpp @@ -11,7 +11,7 @@ #include "siwg.h" #include "siwg_jni.h" -#include "private_siwg_callback.h" +#include "siwg_callback.h" #include "com_aterve_siwg_SiwgJNI.h" static bool luaL_checkbool(lua_State *L, int numArg) @@ -265,7 +265,6 @@ static void LuaInit(lua_State* L) SETCONSTANT(STATUS_SUCCESS) SETCONSTANT(STATUS_FAILED) - SETCONSTANT(STATUS_CONFLICT) #undef SETCONSTANT lua_pop(L, 1); diff --git a/siwg/src/siwg.h b/siwg/src/siwg.h index 131ac0b..b72e6d8 100644 --- a/siwg/src/siwg.h +++ b/siwg/src/siwg.h @@ -13,5 +13,4 @@ enum STATUS { STATUS_SUCCESS = 1, STATUS_FAILED = 2, - STATUS_CONFLICT = 4, }; diff --git a/siwg/src/siwg_callback.cpp b/siwg/src/siwg_callback.cpp index 3383cec..0eee991 100644 --- a/siwg/src/siwg_callback.cpp +++ b/siwg/src/siwg_callback.cpp @@ -1,5 +1,5 @@ #if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_ANDROID) -#include "private_siwg_callback.h" +#include "siwg_callback.h" #include static SIWG_callback m_callback; diff --git a/siwg/src/private_siwg_callback.h b/siwg/src/siwg_callback.h similarity index 100% rename from siwg/src/private_siwg_callback.h rename to siwg/src/siwg_callback.h