Implement mutual buddy relationship

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

longnt
Posts: 19
Joined: 16 Oct 2020, 02:02

Implement mutual buddy relationship

Postby longnt » 13 Oct 2021, 13:57

Hi.
I'm trying to implement the mutual buddy relationship using the BuddyStorage custom class
So my team have a database that contains all the relationship of my friend system implemented in backend
In the BuddyStorage custom class I've implemented a way that I can load the relationship list from my database to create a BuddyList in the smartfox system when user is logged in by using the method

Code: Select all

loadList(String userName)

But now when User A removes User B from its buddy list I also need that User A is removed from User B's list but the storage don't have any event that indicate when a user is remove from the buddy list of other user
How can I implemented the mutual list for this kind of situation, does the

Code: Select all

saveList(String userName, StorableBuddyList buddyList)
call when ever a change in a buddy list of a user?

How can I access a BuddyStorage instance of a Zone so that I can implement my own logic for this if the saveList method are not called when the buddy update event come?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Implement mutual buddy relationship

Postby Lapo » 14 Oct 2021, 08:00

Hi,
I am not sure why you need an event fired by the storage to know when User A wants to remove User B from his buddy list.
Supposing that User A sends a request to the server to say "Hey, remove User B from my buddy list", that should be the trigger for running both operations. In other words:

    1) Remove B from A's buddy list
    2) Remove A from B's buddy list

Makes sense?
Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
longnt
Posts: 19
Joined: 16 Oct 2020, 02:02

Re: Implement mutual buddy relationship

Postby longnt » 16 Oct 2021, 19:14

Hi,
Thanks for your response, what I need is this operation can still be call even when user B is not online at the moment user A sending the "Remove B from my buddy list"
Since the SFSBuddyAPI only have option to remove buddy only when the owner is online

Can I do something like this?
- User A remove B from his buddy list, the request is resolved on my backend database
- When user B is online, using the storage custom class, I load the friend list of user B from my backend database then re-populate the entire user B's buddy list. So that the event BUDDY_LIST_INIT of user B will have correct buddy list.

I'm implementing this right now but need to wait for my backend database to implement this so I need to know first will this right way to do in this kind of situation.

Cheer!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Implement mutual buddy relationship

Postby Lapo » 18 Oct 2021, 13:06

Hi,
yes you need a custom persistence class. Using a database for storage is a good choice, especially if you plan to have 100s or 1000s of buddy lists.

As regards the offline removal of a buddy, you're using the correct approach.
When User A removes User B and User B is offline, you can go directly at the storage level and remove User A from B's list.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
longnt
Posts: 19
Joined: 16 Oct 2020, 02:02

Re: Implement mutual buddy relationship

Postby longnt » 25 Oct 2021, 09:04

Hi,
I've implemented my custom Buddy Storage class and load user's Buddy List from my backend like this

Code: Select all

    @Override
    public BuddyList loadList(String ownerName) throws SFSBuddyListNotFoundException, IOException {
        System.out.println("Loading buddy list for:" + ownerName);
        User user = zone.getUserByName(ownerName);
        String token = user.getVariable("token").getStringValue();
        BuddyList list = RestClient.loadBuddyList(ownerName, token, buddyListManager);
        return list;
    }

but for some reason I'm having this exception

Code: Select all

 [SFSWorker:Sys:4] v290.SystemReqController     - java.lang.NullPointerException
        com.smartfoxserver.v2.buddylist.DefaultBuddySerializer.getRelatedUser(DefaultBuddySerializer.java:37)
        com.smartfoxserver.v2.buddylist.DefaultBuddySerializer.serialize(DefaultBuddySerializer.java:14)
        com.smartfoxserver.v2.buddylist.SFSBuddy.toSFSArray(SFSBuddy.java:239)
        com.smartfoxserver.v2.buddylist.SFSBuddyList.toSFSArray(SFSBuddyList.java:245)
        com.smartfoxserver.v2.api.response.DefaultBuddyInitSerializer.serialize(DefaultBuddyInitSerializer.java:14)
        com.smartfoxserver.v2.api.response.SFSBuddyResponseApi.notifyBuddyListInited(SFSBuddyResponseApi.java:108)
        com.smartfoxserver.v2.api.SFSBuddyApi.initBuddyList(SFSBuddyApi.java:93)
        com.smartfoxserver.v2.controllers.system.buddylist.InitBuddyList.execute(InitBuddyList.java:32)
        com.smartfoxserver.v2.controllers.v290.SystemReqController.processRequest(SystemReqController.java:172)
        com.smartfoxserver.v2.controllers.v290.SystemReqController.enqueueRequest(SystemReqController.java:127)
        com.smartfoxserver.bitswarm.io.protocols.AbstractProtocolCodec.dispatchRequestToController(AbstractProtocolCodec.java:39)
        com.smartfoxserver.v2.protocol.SFSProtocolCodec.dispatchRequest(SFSProtocolCodec.java:133)
        com.smartfoxserver.v2.protocol.SFSProtocolCodec.onPacketRead(SFSProtocolCodec.java:90)
        com.smartfoxserver.v2.protocol.binary.BinaryIoHandler$1.run(BinaryIoHandler.java:477)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        java.lang.Thread.run(Thread.java:748)


Because of this the user cannot init their buddy list, what could go wrong on this one?

Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Implement mutual buddy relationship

Postby Lapo » 25 Oct 2021, 16:26

Hi,
I would recommend to check that the list returned by the RestClient.loadBuddyList method does not contain null objects.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 69 guests