diff --git a/README.md b/README.md index 58826ad..e6817de 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ isn't quite there yet. At the time of writing, the following are implemented. ### Ecom interface - Catalog offers (query/count/copy) -- Entitlements (query/count/copy) +- Entitlements (query/count/copy), entitlement token If there's something missing that you need, please do open an issue. PRs are very welcome. diff --git a/src/main/java/com/bearwaves/eos4j/EOSEcom.java b/src/main/java/com/bearwaves/eos4j/EOSEcom.java index 26cfab5..473daca 100644 --- a/src/main/java/com/bearwaves/eos4j/EOSEcom.java +++ b/src/main/java/com/bearwaves/eos4j/EOSEcom.java @@ -50,6 +50,10 @@ public Entitlement copyEntitlementByNameAndIndex(CopyEntitlementByNameAndIndexOp return EOSEcomNative.copyEntitlementByNameAndIndex(handle, options); } + public void queryEntitlementToken(QueryEntitlementTokenOptions options, OnQueryEntitlementTokenCallback callback) { + EOSEcomNative.queryEntitlementToken(handle, options, callback); + } + public static class CatalogOffer extends EOSHandle { public final int serverIndex; public final String catalogNamespace; @@ -141,6 +145,8 @@ public void release() { } } + // Options structs + public static class QueryOffersOptions { public final EOS.EpicAccountId localUserId; public final String overrideCatalogNamespace; @@ -241,11 +247,23 @@ public CopyEntitlementByNameAndIndexOptions(EOS.EpicAccountId localUserId, Strin } } + public static class QueryEntitlementTokenOptions { + public final EOS.EpicAccountId localUserId; + public final String[] entitlementNames; + + public QueryEntitlementTokenOptions(EOS.EpicAccountId localUserId, String[] entitlementNames) { + this.localUserId = localUserId; + this.entitlementNames = entitlementNames; + } + } + + // Callback structs + public static class QueryOffersCallbackInfo { public final int resultCode; public final EOS.EpicAccountId localUserId; - public QueryOffersCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) { + QueryOffersCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) { this.resultCode = resultCode; this.localUserId = localUserId; } @@ -255,12 +273,26 @@ public static class QueryEntitlementsCallbackInfo { public final int resultCode; public final EOS.EpicAccountId localUserId; - public QueryEntitlementsCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) { + QueryEntitlementsCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) { this.resultCode = resultCode; this.localUserId = localUserId; } } + public static class QueryEntitlementTokenCallbackInfo { + public final int resultCode; + public final EOS.EpicAccountId localUserId; + public final String entitlementToken; + + QueryEntitlementTokenCallbackInfo(int resultCode, EOS.EpicAccountId localUserId, String entitlementToken) { + this.resultCode = resultCode; + this.localUserId = localUserId; + this.entitlementToken = entitlementToken; + } + } + + // Callback interfaces + public interface OnQueryOffersCompleteCallback { void run(QueryOffersCallbackInfo data); } @@ -268,4 +300,8 @@ public interface OnQueryOffersCompleteCallback { public interface OnQueryEntitlementsCallback { void run(QueryEntitlementsCallbackInfo data); } + + public interface OnQueryEntitlementTokenCallback { + void run(QueryEntitlementTokenCallbackInfo data); + } } diff --git a/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java b/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java index c789be1..ec978e3 100644 --- a/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java +++ b/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java @@ -353,5 +353,45 @@ static native EOSEcom.Entitlement copyEntitlementByNameAndIndex( static native void releaseEntitlement(long handle); /* EOS_Ecom_Entitlement_Release(reinterpret_cast(handle)); */ + + static native void queryEntitlementToken( + long handle, + EOSEcom.QueryEntitlementTokenOptions options, + EOSEcom.OnQueryEntitlementTokenCallback callback + ); /* + jobject local_user_id_obj = EOS4J::javaObjectFromObjectField(env, options, "localUserId", "Lcom/bearwaves/eos4j/EOS$EpicAccountId;"); + auto local_user_id = EOS4J::javaLongFromObjectField(env, local_user_id_obj, "ptr"); + + std::vector entitlement_names = EOS4J::javaStringVectorFromObjectField(env, options, "entitlementNames"); + const char* entitlements[entitlement_names.size()]; + for (size_t i = 0; i < entitlement_names.size(); i++) { + entitlements[i] = entitlement_names.at(i).c_str(); + } + + EOS_Ecom_QueryEntitlementTokenOptions query_options; + memset(&query_options, 0, sizeof(query_options)); + query_options.ApiVersion = EOS_ECOM_QUERYENTITLEMENTTOKEN_API_LATEST; + query_options.LocalUserId = reinterpret_cast(local_user_id); + query_options.EntitlementNames = reinterpret_cast(entitlements); + query_options.EntitlementNameCount = entitlement_names.size(); + + auto callback_adapter = std::make_unique(env, callback); + EOS_Ecom_QueryEntitlementToken(reinterpret_cast(handle), &query_options, callback_adapter.release(), [](const EOS_Ecom_QueryEntitlementTokenCallbackInfo* data) -> void { + std::unique_ptr callback_adapter{reinterpret_cast(data->ClientData)}; + callback_adapter->attach([&](JNIEnv* env, jobject callback) -> void { + jclass eaid_cls = env->FindClass("com/bearwaves/eos4j/EOS$EpicAccountId"); + jmethodID eaid_ctor = env->GetMethodID(eaid_cls, "", "(J)V"); + auto local_user_id = env->NewObject(eaid_cls, eaid_ctor, data->LocalUserId); + + jclass callback_info_class = env->FindClass("com/bearwaves/eos4j/EOSEcom$QueryEntitlementTokenCallbackInfo"); + jmethodID callback_info_ctor = env->GetMethodID(callback_info_class, "", "(ILcom/bearwaves/eos4j/EOS$EpicAccountId;Ljava/lang/String;)V"); + auto callback_info = env->NewObject(callback_info_class, callback_info_ctor, static_cast(data->ResultCode), local_user_id, env->NewStringUTF(data->EntitlementToken)); + + jclass cls = env->GetObjectClass(callback); + jmethodID mid = env->GetMethodID(cls, "run", "(Lcom/bearwaves/eos4j/EOSEcom$QueryEntitlementTokenCallbackInfo;)V"); + env->CallVoidMethod(callback, mid, callback_info); + }); + }); + */ }