diff --git a/build/android/app/src/main/java/com/multicraft/game/GameActivity.kt b/build/android/app/src/main/java/com/multicraft/game/GameActivity.kt index 448b20615..ee5f1c090 100644 --- a/build/android/app/src/main/java/com/multicraft/game/GameActivity.kt +++ b/build/android/app/src/main/java/com/multicraft/game/GameActivity.kt @@ -220,6 +220,10 @@ class GameActivity : SDLActivity() { fun upgrade(item: String) { } + fun getSecretKey(key: String): String { + return "Stub" + } + @Suppress("unused") fun getRoundScreen(): Int { return radius diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 4228bd5aa..80d90c2bd 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -392,7 +392,7 @@ jstring getJniString(const std::string &message) void upgrade(const std::string &item) { jmethodID upgradeGame = jnienv->GetMethodID(activityClass, - "upgrade","(Ljava/lang/String;)V"); + "upgrade", "(Ljava/lang/String;)V"); FATAL_ERROR_IF(upgradeGame == nullptr, "porting::upgradeGame unable to find java upgrade method"); @@ -418,4 +418,18 @@ int getRoundScreen() } return radius; } + +std::string getSecretKey(const std::string &key) +{ + jmethodID getKey = jnienv->GetMethodID(activityClass, + "getSecretKey", "(Ljava/lang/String;)Ljava/lang/String;"); + + FATAL_ERROR_IF(getKey == nullptr, + "porting::getSecretKey unable to find java getSecretKey method"); + + jstring jkey = jnienv->NewStringUTF(key.c_str()); + auto result = (jstring) jnienv->CallObjectMethod(activityObj, getKey, jkey); + + return javaStringToUTF8(result); +} } diff --git a/src/porting_android.h b/src/porting_android.h index 0d4e97c35..65976b8d3 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -113,4 +113,9 @@ void upgrade(const std::string &item); * get radius of rounded corners */ int getRoundScreen(); + +/** + * get encrypted key for further actions + */ +std::string getSecretKey(const std::string &key); } diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 138f0a879..6798b2d2a 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -501,6 +501,21 @@ int ModApiUtil::l_upgrade(lua_State *L) return 1; } +int ModApiUtil::l_get_secret_key(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; +#if defined(__ANDROID__) || defined(__IOS__) + const std::string secret_name = luaL_checkstring(L, 1); + const std::string res = porting::getSecretKey(secret_name); + lua_pushlstring(L, res.c_str(), res.size()); +#else + // Not implemented on desktop platforms + lua_pushstring(L, ""); +#endif + + return 1; +} + void ModApiUtil::Initialize(lua_State *L, int top) { API_FCT(log); @@ -597,4 +612,5 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top) void ModApiUtil::InitializeMainMenu(lua_State *L, int top) { Initialize(L, top); API_FCT(upgrade); + API_FCT(get_secret_key); } diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index 2d8812c6b..e2889babf 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -104,6 +104,9 @@ private: // upgrade(string) static int l_upgrade(lua_State *L); + // get_secret_key(string) + static int l_get_secret_key(lua_State *L); + public: static void Initialize(lua_State *L, int top); static void InitializeAsync(lua_State *L, int top);