Skip to content

Commit

Permalink
Add ownership token
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Jan 19, 2024
1 parent 925fcc2 commit 5f6bfca
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ isn't quite there yet. At the time of writing, the following are implemented.

- Catalog offers (query/count/copy)
- Entitlements (query/count/copy), entitlement token
- Query ownership
- Query ownership, ownership token

If there's something missing that you need, please do open an issue. PRs
are very welcome.
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcom.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public void queryOwnership(QueryOwnershipOptions options, OnQueryOwnershipCallba
EOSEcomNative.queryOwnership(handle, options, callback);
}

public void queryOwnershipToken(QueryOwnershipTokenOptions options, OnQueryOwnershipTokenCallback callback) {
EOSEcomNative.queryOwnershipToken(handle, options, callback);
}

public static class CatalogOffer extends EOSHandle {
public final int serverIndex;
public final String catalogNamespace;
Expand Down Expand Up @@ -283,6 +287,18 @@ public QueryOwnershipOptions(EOS.EpicAccountId localUserId, String[] catalogItem
}
}

public static class QueryOwnershipTokenOptions {
public final EOS.EpicAccountId localUserId;
public final String[] catalogItemIds;
public final String catalogNamespace;

public QueryOwnershipTokenOptions(EOS.EpicAccountId localUserId, String[] catalogItemIds, String catalogNamespace) {
this.localUserId = localUserId;
this.catalogItemIds = catalogItemIds;
this.catalogNamespace = catalogNamespace;
}
}

// Callback structs

public static class QueryOffersCallbackInfo {
Expand Down Expand Up @@ -329,6 +345,18 @@ public static class QueryOwnershipCallbackInfo {
}
}

public static class QueryOwnershipTokenCallbackInfo {
public final int resultCode;
public final EOS.EpicAccountId localUserId;
public final String ownershipToken;

QueryOwnershipTokenCallbackInfo(int resultCode, EOS.EpicAccountId localUserId, String ownershipToken) {
this.resultCode = resultCode;
this.localUserId = localUserId;
this.ownershipToken = ownershipToken;
}
}

// Callback interfaces

public interface OnQueryOffersCompleteCallback {
Expand All @@ -347,6 +375,10 @@ public interface OnQueryOwnershipCallback {
void run(QueryOwnershipCallbackInfo data);
}

public interface OnQueryOwnershipTokenCallback {
void run(QueryOwnershipTokenCallbackInfo data);
}

// Enums

public enum OwnershipStatus {
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcomNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,49 @@ static native void queryOwnership(
});
});
*/

static native void queryOwnershipToken(
long handle,
EOSEcom.QueryOwnershipTokenOptions options,
EOSEcom.OnQueryOwnershipTokenCallback 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");
auto catalog_namespace = EOS4J::javaStringFromObjectField(env, options, "catalogNamespace");
std::vector<EOS4J::JavaString> catalog_item_ids = EOS4J::javaStringVectorFromObjectField(env, options, "catalogItemIds");
const char* item_ids[catalog_item_ids.size()];
for (size_t i = 0; i < catalog_item_ids.size(); i++) {
item_ids[i] = catalog_item_ids.at(i).c_str();
}
EOS_Ecom_QueryOwnershipTokenOptions query_options;
memset(&query_options, 0, sizeof(query_options));
query_options.ApiVersion = EOS_ECOM_QUERYOWNERSHIPTOKEN_API_LATEST;
query_options.LocalUserId = reinterpret_cast<EOS_EpicAccountId>(local_user_id);
query_options.CatalogItemIds = reinterpret_cast<EOS_Ecom_CatalogItemId*>(item_ids);
query_options.CatalogItemIdCount = catalog_item_ids.size();
if (catalog_namespace) {
query_options.CatalogNamespace = catalog_namespace->c_str();
}
auto callback_adapter = std::make_unique<EOS4J::CallbackAdapter>(env, callback);
EOS_Ecom_QueryOwnershipToken(reinterpret_cast<EOS_HEcom>(handle), &query_options, callback_adapter.release(), [](const EOS_Ecom_QueryOwnershipTokenCallbackInfo* data) -> void {
std::unique_ptr<EOS4J::CallbackAdapter> callback_adapter{reinterpret_cast<EOS4J::CallbackAdapter*>(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, "<init>", "(J)V");
auto local_user_id = env->NewObject(eaid_cls, eaid_ctor, data->LocalUserId);
jclass callback_info_class = env->FindClass("com/bearwaves/eos4j/EOSEcom$QueryOwnershipTokenCallbackInfo");
jmethodID callback_info_ctor = env->GetMethodID(callback_info_class, "<init>", "(ILcom/bearwaves/eos4j/EOS$EpicAccountId;Ljava/lang/String;)V");
auto callback_info = env->NewObject(callback_info_class, callback_info_ctor, static_cast<int>(data->ResultCode), local_user_id, env->NewStringUTF(data->OwnershipToken));
jclass cls = env->GetObjectClass(callback);
jmethodID mid = env->GetMethodID(cls, "run", "(Lcom/bearwaves/eos4j/EOSEcom$QueryOwnershipTokenCallbackInfo;)V");
env->CallVoidMethod(callback, mid, callback_info);
});
});
*/
}

0 comments on commit 5f6bfca

Please sign in to comment.