question

en.karam1989 avatar image
en.karam1989 asked

CloudScript CreateSharedGroup if not exists

Dear all:

I'm using CloudScript to implement the friendship requests.

Where a player sends a request to the other, the other should see the requests and choose to accept/ cancel the request.

 

As mentioned in previous posts, I'm using CloudScript to CreateSharedGroup with SharedGroupId related to the receiver PlayfabId, and store the requests (Sender PlayfabIds) in it.

And then use GetSharedGroupData and UpdateSharedGroupDate for later requests

 

The problem is:
You can't check if the there is a SharedGroup with id=x or not
(To create a group when it doesn't exist, and update it if it exists)


There is no such method to do it, could you help please.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Sure thing - the way to do this would be to check for the "InvalidSharedGroupId" error when reading the shared group data via the Server API call. If you see that error, you know that the group does not exist (and so, in this case, should be created).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

en.karam1989 avatar image
en.karam1989 answered

Yes actually I've done it the same way you told, But I think there should be a method to test the existence of a SharedGroupId, better than catching an error to know the absence of it.

 

Thanks a lot for your response

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

I'll add a backlog item for that, but currently, this would be the correct way to test for the existence of a shared group data ID.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

I'm using this code:

    try {
       createSharedGroup(sharedGroupId);
    } catch (e){
        if (!undefinedOrNull(e.Error) && e.Error.error === "InvalidSharedGroupId"){
            // shared group already exists
        } else {
            // handler other errors: "native JS ones" or "PlayFab custom ones"
        }
    }

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andres Urquijo avatar image
Andres Urquijo answered

@Brendan I tried doing the error check you are suggesting within the Unity framework. However I'm not getting any errors from GetSharedGroupData calls, even when trying to read from group IDs that surely do not exist (like "randomgroup26").

My current approach is to check the Members list from the result. and if that is empty or null, I create the group.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

To be clear, the error is returned for the Server API call - not the Client API. This is specifically because clients that do not know about a given Shared Group should not be able go "fishing" for valid IDs.

0 Likes 0 ·
brendan avatar image brendan brendan commented ·

I've updated the answer above, to clarify this.

0 Likes 0 ·
Andres Urquijo avatar image Andres Urquijo brendan commented ·

That makes sense! I'm actually in the process of moving some more of the logic over to cloudscript as it seems to be a better place for what I'm doing anyways (user registration). So that works out for me.

Wouldn't my previous work-around allow you to do that fishing you want to prevent? Thanks for the quick response.

0 Likes 0 ·
brendan avatar image brendan Andres Urquijo commented ·

Our general advice is to never add a player to a Shared Group Data directly, since that gives the client read/write access to the data (allowing a hacked client to write anything at all to it). But if you add players directly, then yes, that would allow people to at least see that the data object exists.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.