How to check when server updates client with UserManager list.

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

Moderators: Lapo, Bax

User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

How to check when server updates client with UserManager list.

Postby Aet » 12 Apr 2021, 23:36

Hi,

I have some code which updates a user with the positions for all other users in the room upon entering the room for the first time.
A separate system batches changes in user position and updates all users on an interval after joining. There can be too many users in one room for standard User Variables to work with these values, luckily we don't need a very high rate of update.

So the issue is when it sends this update on a USER_JOIN_ROOM event, the client hasn't updated the UserManager user list for their new room, so the update I send fails because all the user Ids do not match up with existing users on the client.

I can fix this clientside blocking the update until the user loads the scene in Unity which happens after the room is joined, but was wondering if there is a way to detect this serverside?

Is there a way serverside to tell when the update is sent to the client about other users in the room. If so I can just send our update after since it is all tcp based. Or do you recommend I just go with this clientside solution?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to check when server updates client with UserManager list.

Postby Lapo » 13 Apr 2021, 07:46

Hello,
we need a clarification:
So the issue is when it sends this update on a USER_JOIN_ROOM event, the client hasn't updated the UserManager user list for their new room, so the update I send fails because all the user Ids do not match up with existing users on the client.

This sounds strange because the client update (i.e. the SFSEvent.ROOM_JOIN) is sent before the server side event is triggered, therefore an update generated from the Extension would arrive after the client is updated.

I've done a quick test with a Java client and I can confirm that even locally (with negligible lag) the Extension message sent via the ROOM_JOIN listener arrives at the client after the relative Room List has been populated on the client.

Can you clarify this point?
Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

Re: How to check when server updates client with UserManager list.

Postby Aet » 13 Apr 2021, 18:38

Sure thing,

This is all tested locally

On the SFSEventType.USER_JOIN_ROOM event handler I send an extension message to the client. Among other things this message has a SFSObject with a relationship from user Ids to another SFSObject which is a list of batched variables and their values.

The client receives this message however UserManager.GetUserById will fail for these ids and return null.

Clientside I have a handler for SFSEvent.ROOM_JOIN, this handler will load the scene in Unity, and once the scene finishes loading I can check UserManager.GetUserById on the received ids and they return with the actual users.

Very odd, I'm unsure how we are getting this behavior if that is how it works on the backend. I suppose our solution is working so I am not too concerned, but would like to figure it out.

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

Re: How to check when server updates client with UserManager list.

Postby Lapo » 14 Apr 2021, 07:35

Thanks. A couple more questions:

1) can you confirm that on client side the SFSEvent.ROOM_JOIN is received before the custom Extension message?
2) when you say this:
The client receives this message however UserManager.GetUserById will fail for these ids and return null.

You mean user ids from the Room that has just been joined? Correct?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

Re: How to check when server updates client with UserManager list.

Postby Aet » 14 Apr 2021, 08:22

1) I can double check this, but it appeared to be the case in earlier testing.
2) Yes, that is the case. I can confirm the users are in the room, and if I just delay the check for a second then it works correctly because the ids are correct.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to check when server updates client with UserManager list.

Postby Lapo » 14 Apr 2021, 08:52

Aet wrote:1) I can double check this, but it appeared to be the case in earlier testing.
2) Yes, that is the case. I can confirm the users are in the room, and if I just delay the check for a second then it works correctly because the ids are correct.


Thanks.
We'll try to reproduce it in C#/Unity as my quick test was done with a Java client.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to check when server updates client with UserManager list.

Postby Lapo » 15 Apr 2021, 08:23

UPDATE:
We tested a similar scenario in Unity / C# without finding any issue.
Here's an outline of the test:

- We have a Room X with three NPCs already connected
- We start a Unity client that connects, logs in and joins Room X
- Server side Extension sends the id(s) of the three NPCs to the client on SFSEvent.USER_JOIN_ROOM
- Client handles the Ext. event and searches the received id(s) in the lastJoinedRoom.

On the client side we notice that the ROOM_JOIN event is always triggered before the custom Extension event, and the User ids are always present in the local client data.

The test was done with the latest C# API (1.7.13) and a previous version (1.7.9)

Maybe there's some other detail that is missing from your use case.
Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

Re: How to check when server updates client with UserManager list.

Postby Aet » 15 Apr 2021, 17:46

Appreciate the look into it. Thanks Lapo!

I'll look into any differences on my end, I'm not sure what might be causing that differing behavior. But good to know it isn't expected. Hmm...

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Bing [Bot] and 56 guests