Skip to content

Commit

Permalink
Add queryOwnership
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Jan 19, 2024
1 parent 20944c1 commit 925fcc2
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +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

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

public void queryOwnership(QueryOwnershipOptions options, OnQueryOwnershipCallback callback) {
EOSEcomNative.queryOwnership(handle, options, callback);
}

public static class CatalogOffer extends EOSHandle {
public final int serverIndex;
public final String catalogNamespace;
Expand Down Expand Up @@ -145,6 +149,16 @@ public void release() {
}
}

public static class ItemOwnership {
public final String id;
public final OwnershipStatus ownershipStatus;

public ItemOwnership(String id, OwnershipStatus ownershipStatus) {
this.id = id;
this.ownershipStatus = ownershipStatus;
}
}

// Options structs

public static class QueryOffersOptions {
Expand Down Expand Up @@ -257,6 +271,18 @@ public QueryEntitlementTokenOptions(EOS.EpicAccountId localUserId, String[] enti
}
}

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

public QueryOwnershipOptions(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 @@ -291,6 +317,18 @@ public static class QueryEntitlementTokenCallbackInfo {
}
}

public static class QueryOwnershipCallbackInfo {
public final int resultCode;
public final EOS.EpicAccountId localUserId;
public final ItemOwnership[] itemOwnerships;

QueryOwnershipCallbackInfo(int resultCode, EOS.EpicAccountId localUserId, ItemOwnership[] itemOwnerships) {
this.resultCode = resultCode;
this.localUserId = localUserId;
this.itemOwnerships = itemOwnerships;
}
}

// Callback interfaces

public interface OnQueryOffersCompleteCallback {
Expand All @@ -304,4 +342,29 @@ public interface OnQueryEntitlementsCallback {
public interface OnQueryEntitlementTokenCallback {
void run(QueryEntitlementTokenCallbackInfo data);
}

public interface OnQueryOwnershipCallback {
void run(QueryOwnershipCallbackInfo data);
}

// Enums

public enum OwnershipStatus {
NOT_OWNED, OWNED;

static final OwnershipStatus[] values;

static {
values = OwnershipStatus.values();
}

static OwnershipStatus fromInt(int i) {
for (OwnershipStatus value : values) {
if (value.ordinal() == i) {
return value;
}
}
return null;
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcomNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,62 @@ static native void queryEntitlementToken(
});
});
*/

static native void queryOwnership(
long handle,
EOSEcom.QueryOwnershipOptions options,
EOSEcom.OnQueryOwnershipCallback 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_QueryOwnershipOptions query_options;
memset(&query_options, 0, sizeof(query_options));
query_options.ApiVersion = EOS_ECOM_QUERYOWNERSHIP_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_QueryOwnership(reinterpret_cast<EOS_HEcom>(handle), &query_options, callback_adapter.release(), [](const EOS_Ecom_QueryOwnershipCallbackInfo* 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 ownership_cls = env->FindClass("com/bearwaves/eos4j/EOSEcom$ItemOwnership");
jmethodID ownership_ctor = env->GetMethodID(ownership_cls, "<init>", "(Ljava/lang/String;Lcom/bearwaves/eos4j/EOSEcom$OwnershipStatus;)V");
jclass ownership_status_cls = env->FindClass("com/bearwaves/eos4j/EOSEcom$OwnershipStatus");
jmethodID ownership_status_ctor = env->GetStaticMethodID(ownership_status_cls, "fromInt", "(I)Lcom/bearwaves/eos4j/EOSEcom$OwnershipStatus;");
jobjectArray ownerships = env->NewObjectArray(data->ItemOwnershipCount, ownership_cls, nullptr);
for (int i = 0; i < data->ItemOwnershipCount; i++) {
jobject status = env->CallStaticObjectMethod(ownership_status_cls, ownership_status_ctor, data->ItemOwnership[i].OwnershipStatus);
jobject ownership = env->NewObject(ownership_cls, ownership_ctor, env->NewStringUTF(data->ItemOwnership[i].Id), status);
env->SetObjectArrayElement(ownerships, i, ownership);
}
jclass callback_info_class = env->FindClass("com/bearwaves/eos4j/EOSEcom$QueryOwnershipCallbackInfo");
jmethodID callback_info_ctor = env->GetMethodID(callback_info_class, "<init>", "(ILcom/bearwaves/eos4j/EOS$EpicAccountId;[Lcom/bearwaves/eos4j/EOSEcom$ItemOwnership;)V");
auto callback_info = env->NewObject(callback_info_class, callback_info_ctor, static_cast<int>(data->ResultCode), local_user_id, ownerships);
jclass cls = env->GetObjectClass(callback);
jmethodID mid = env->GetMethodID(cls, "run", "(Lcom/bearwaves/eos4j/EOSEcom$QueryOwnershipCallbackInfo;)V");
env->CallVoidMethod(callback, mid, callback_info);
});
});
*/
}

0 comments on commit 925fcc2

Please sign in to comment.