User variables with MMORoom and AOI

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
YoungDeveloper
Posts: 48
Joined: 02 Mar 2014, 21:38
Location: Latvia

User variables with MMORoom and AOI

Postby YoungDeveloper » 05 May 2022, 14:07

Hi, I have couple questions regarding some problems:

What we want:
By default ProximityList sends addedUsers, removedUsers, which is great. But for each user we have to save additional information, like skin id string and rotation float, animation states integers.

Possible solution:
Save these values with user variables using getApi().setUserVariables()
But by reading docs, I understand that changing or updating user variables-properties those changes will be sent to at all room users, but we need only MMORoom AOI range to be notified.

Maybe there is some sort of server handler or event so we can manually filter to whom these user property changes are sent to ?

Thanks

edit:
What is the expected logic for updating user variables server side ?

1. user.getVariables()
2. altering & updating collection
3. getApi().setUserVariables()

Is this correct ?
And there is no automatic logic for managing duplicates (in case of updating existing variable) i have manage those myself, correct ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variables with MMORoom and AOI

Postby Lapo » 06 May 2022, 08:00

Hi,
YoungDeveloper wrote:
What we want:
By default ProximityList sends addedUsers, removedUsers, which is great. But for each user we have to save additional information, like skin id string and rotation float, animation states integers.

Possible solution:
Save these values with user variables using getApi().setUserVariables()
But by reading docs, I understand that changing or updating user variables-properties those changes will be sent to at all room users, but we need only MMORoom AOI range to be notified.

The docs in the MMO Sections says that "UserVariables will work normally in MMORooms, affecting only those Users who are within the AoI of the request sender."
http://docs2x.smartfoxserver.com/Advanc ... /mmo-rooms
So I think this is what you're looking for.

What is the expected logic for updating user variables server side ?

1. user.getVariables()
2. altering & updating collection
3. getApi().setUserVariables()

Is this correct ?

Yes that's a good way to do it.
You can also just create a new collections with new values, if that's more convenient. It just depends on what you need to do.

And there is no automatic logic for managing duplicates (in case of updating existing variable) i have manage those myself, correct ?

Every variable has a name so duplicates are not possible. If you set the variable with name "Test" twice the last value overwrites the previous one. You don't end up with two variables.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
YoungDeveloper
Posts: 48
Joined: 02 Mar 2014, 21:38
Location: Latvia

Re: User variables with MMORoom and AOI

Postby YoungDeveloper » 06 May 2022, 11:05

Okay nice then we will use user variables for mmo user properties like skin id.

What about attaching additional data to proximity list callback ?
Because server will send position and rotation updates to users via UDP so storing that in user variables will be unneeded overhead.

How planned setup works:

1. User gets proximity list with addedUsers. Users should be spawned with proper initial position and rotation.
2. User get updates from every user updated position and rotation via custom client request from server via UDP.

Here is the challenge.

When spawning new users we set position from user.AoiEntryPoint but what about rotation ?
As we need to set it once only and after its updated via udp. Adding it via user variables will result it in being sent tcp.

So the challenge is to send it once on spawn, basically same thing as user.AoiEntryPoint but "AoiEntryRotation"

If we could attach additional data to proximityList callback we could plug in all initial metadata we need, like 'addedUsersRotations' list.
What could be solutions to solve this ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variables with MMORoom and AOI

Postby Lapo » 06 May 2022, 12:34

The proximity list callback tells every client who else is "around" them, within the limits of the AoI.
I am not sure what other data you need to send. I mean other than User's properties.
Rotation is still User's property so it could be set via User Variables, at least just to set the initial rotation as you said, so that the relative avatar is rendered with the right rotation when it is spawned.

From there you can send updates via UDP, if that's necessary. From server side you can obtain the proximity list of any player in the Room.
Example:
If player X needs to update everyone around him/her via UDP you can obtain player X's proximity list by calling mmoRoom.getProximityList(userX); and then sending the UDP update to that list of Users.

If we could attach additional data to proximityList callback we could plug in all initial metadata we need, like 'addedUsersRotations' list.
What could be solutions to solve this ?

Isn't it the same as sending every rotation value as User's property?
It also uses less data, because you're not sending a separate data structure that needs to also add references to each player in order to associate each User to each rotation value.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
YoungDeveloper
Posts: 48
Joined: 02 Mar 2014, 21:38
Location: Latvia

Re: User variables with MMORoom and AOI

Postby YoungDeveloper » 06 May 2022, 14:23

YoungDeveloper wrote:2. User get updates from every user updated position and rotation via custom client request from server via UDP.


1. When user position or rotation changes he sends custom extension request to sever with UDP with pos and rot data.
2. Server optionally received this data (because of unreliable protocol), after which we
2.1 Save the position using mmoApi.setUserPosition()
2.2 Send that user data to other proximity users using your mentioned mmoRoom.getProximityList(userX) combined with send(String cmd, ISFSObject packet, proximityUser, useUdp: true)
3. We also need to save that rotation info, which can be user variable as you suggested, but, it cant be a public variable only private server one. Because if we set it as public variable it will be synched to other users with reliable protocol, which we don't need because we send it with UDP point 2.2.

User variables are needed on server side to cache user rotation, but not for transfer itself, so when new addedUsers is fired for user we can attach that rotation info from user private variables for user init purposes and later its updated with UDP.

That's why the question is how to send/attach this info once only to spawn addedUsers each user game character properly, and after we sync with UDP and not reliable user TCP variables. Because then we send that info twice with udp And user variables which doesn't make sense.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variables with MMORoom and AOI

Postby Lapo » 08 May 2022, 10:36

You can set a UserVariable on the server side without triggering the client update.
The SFSApi.setUserVariables() method has this signature:

Code: Select all

setUserVariables(User owner, List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent)

and you can set both booleans to false.

This in turn sets the variable without updating the clients, which already know the rotation values. At the same time if a new player enters the AoI it will receive the latest rotation value via the UserVariables and from that moment on he will also start getting the UDP updates.

I think this should work correctly.
Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
YoungDeveloper
Posts: 48
Joined: 02 Mar 2014, 21:38
Location: Latvia

Re: User variables with MMORoom and AOI

Postby YoungDeveloper » 09 May 2022, 08:28

This perfectly solved the initial rotation problem. Thank you.

One little clarification: getApi().setUserVariables works more like append and not set ?
Consider this scenario..

getApi().setUserVariables(user, asList(SFSUserVariable.newInstance("a", 10), SFSUserVariable.newInstance("b", 100)), false, false);
getApi().setUserVariables(user, asList(SFSUserVariable.newInstance("a", 20), SFSUserVariable.newInstance("c", 1000)), false, false);

result will be user containing 3 variables:
a: 20
b: 100
c: 1000

Is this correct ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variables with MMORoom and AOI

Postby Lapo » 09 May 2022, 09:02

Yes, you could think it that way.
Once a variable has been set it stays there until you modify it or remove it. Adding new variables does not affect the old ones.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
YoungDeveloper
Posts: 48
Joined: 02 Mar 2014, 21:38
Location: Latvia

Re: User variables with MMORoom and AOI

Postby YoungDeveloper » 09 May 2022, 10:55

Thank you for your time and great help as usual, have a great week :arrow:

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 58 guests