Room Extension and USER_VARIABLES_UPDATE Events

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

Moderators: Lapo, Bax

Majiy
Posts: 5
Joined: 06 Jan 2011, 19:29

Room Extension and USER_VARIABLES_UPDATE Events

Postby Majiy » 06 Jan 2011, 19:43

I´m trying to write my first Extension right now. It is a Room Level Extension.

I successfully managed to register a request handler, and now I´m trying to implement an EventHandler, to listen to USER_VARIABLES_UPDATE events, but no luck so far.

The listener is registered in the following way:
addEventHandler( SFSEventType.USER_VARIABLES_UPDATE , UserVariableUpdateEventHandler.class );

The handleServerEvent method of the UserVariableUpdateEventHandler class just traces some text right now, but it never seems to be invoked. I have a client connected and joined in the room, who changes his user variable with a SetUserVariablesRequest. This request seems to have success, because the client catches a SFSEvent.USER_VARIABLES_UPDATE event.

How can I find out why the Extension doesn´t handle this event? Or are room level extensions for some reason not able to catch Variables Updates events?

Thanks for any help.
Majiy
Posts: 5
Joined: 06 Jan 2011, 19:29

Postby Majiy » 07 Jan 2011, 09:33

Just did some more testing: The extension does catch SFSEventType.USER_JOIN_ROOM type events without a problem.

I would guess that no SFSEventType.USER_VARIABLES_UPDATE events are fired in the room at all, but the client catches them without a problem.

Tested this both on RC1A and RC1B, no difference.
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 10 Jan 2011, 16:28

Hi,
the event is not dispatched at Room Level because it is beyond the scope of the Room.

Example:
UserA joins the Zone and goes into Room1
UserB joins the Zone and sets a new UserVariable, called "avatar"

Should the extension in Room1 get the event? NO, because it is irrelevant to the Room.
Probably it should be notified if the User setting the variable was also joined in that Room, however at the moment it is not implemented this way. So if you want to listen for UserVariables changes you should use a Zone Level Extension.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Majiy
Posts: 5
Joined: 06 Jan 2011, 19:29

Postby Majiy » 11 Jan 2011, 12:46

Sure helps, not at least I know that I didn´t mess up something :)

Is it documented somewhere, which kind events are fired to what type of extension? Didn´t find it in the Java Docs.
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 11 Jan 2011, 13:53

Lapo

--

gotoAndPlay()

...addicted to flash games
ktamlyn
Posts: 17
Joined: 04 Sep 2013, 16:25

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby ktamlyn » 05 Sep 2013, 16:15

Its helpful to know that something that is not happening as expected shouldn't happen by design, but I have to say not providing a means to allow Room extensions to receive user variable updates without creating an event system with a Zone extension is weak. This effectively renders User Variables almost useless within a room extension. I followed the documentation's recommendation to use Zone ex as login and create a room extension to manage the room.

What do you recommend to people who want to respond to user variable updates at the room level? The standing advice of "You can't" isn't a recommendation on how to deal with the feature absence. I am truly looking for a recommendation such as "it would be easy to catch the events at the zone level and send them to the room extension if you XYZ".

Your help is much appreciated. Thank you!
Last edited by ktamlyn on 05 Sep 2013, 18:01, edited 2 times in total.
ktamlyn
Posts: 17
Joined: 04 Sep 2013, 16:25

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby ktamlyn » 05 Sep 2013, 16:16

Also, the link is broken now.
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby Lapo » 05 Sep 2013, 19:17

"it would be easy to catch the events at the zone level and send them to the room extension if you XYZ".

Yes it is easy to do :)

1) Catch the event at the Zone Level.
2) Call --> theRoom.getExtension().handleInternalMessage(event)
(where theRoom is your target Room and event is the whole event object)

That's all
Lapo

--

gotoAndPlay()

...addicted to flash games
ktamlyn
Posts: 17
Joined: 04 Sep 2013, 16:25

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby ktamlyn » 05 Sep 2013, 20:13

Thanks!

Next question, related. If I use a room variable instead of a User Variable, when do I know that events will fire?

For example using the following code doesn't result in any user getting an update event:

Code: Select all

RoomVariable rv = new SFSRoomVariable(RoomVariables.ALL_PARTICIPANTS_READY, false);
rv.setGlobal(true);

try {
    room.setVariable(rv);
} catch (SFSVariableException e) {
    e.printStackTrace();
}


Am I forced into something similar to:

Code: Select all

RoomVariable rv = new SFSRoomVariable(RoomVariables.ALL_PARTICIPANTS_READY, true);
rv.setGlobal(true);
List<RoomVariable> listOfVars = Arrays.asList(rv);
parentEx.getApi().setRoomVariables(sessionBean.getFacilitator().getSFSUser(), room, listOfVars, true, false, true);
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby Lapo » 06 Sep 2013, 07:24

Yes you are "forced" to use the server side API :) As we recommend in our documentation:
http://docs2x.smartfoxserver.com/Develo ... ension-api

The first code example is incorrect because it will only create the Room Variable but won't trigger any client update
Lapo

--

gotoAndPlay()

...addicted to flash games
BigApp7e
Posts: 12
Joined: 27 May 2014, 13:59

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby BigApp7e » 18 Sep 2014, 07:23

Update smart fox server version 2.9.0. In my Room level Extension I have this:

Code: Select all

this.addEventHandler (SFSEventType.USER_VARIABLES_UPDATE, OnUserVariableUpdate.class);
/////////////
public class OnUserVariableUpdate extends BaseServerEventHandler
{
Override
public void handleServerEvent (ISFSEvent event) throws SFSException
{
trace ("some variable change");
}
}


When changing a variable

var someVariable: UserVariable = new SFSUserVariable ("value", value);
sfs.send (new SetUserVariablesRequest ([someVariable]));

Extention log in the console have the following:

TWICE ..?

some variable change
some variable change

Why is called two times?
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby Lapo » 18 Sep 2014, 08:52

Are you sure you don't have some other code running somewhere else?
Maybe the same Extension is attached in two places? Like two different Zones? Or a Zone and a Room?

I ask because if I do the same I get one event which tells me that something else is the problem.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
BigApp7e
Posts: 12
Joined: 27 May 2014, 13:59

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby BigApp7e » 18 Sep 2014, 11:02

I do not think so, in Action Script code everything is fine there trace once. Any ideas why room extension траце 2 times?
User avatar
Lapo
Site Admin
Posts: 21353
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby Lapo » 18 Sep 2014, 11:34

But we're talking about server side, not client side.
The only reason why you see the message twice is that you have two listeners for that event on the server side.

Can you double check the Extension is not running in multiple places or, more generally, that you don't have other listeners for that same event in the system?

Other options is that you might be running a very very old version of the server, although we have never heard of such problem even with the earliest release.
Lapo

--

gotoAndPlay()

...addicted to flash games
BigApp7e
Posts: 12
Joined: 27 May 2014, 13:59

Re: Room Extension and USER_VARIABLES_UPDATE Events

Postby BigApp7e » 18 Sep 2014, 12:03

For the moment I have a listener for user variable update which is located in Room Extension. But I'm going to do 10 rooms in all to put this listener. From your answer I understand that this will destroy the system. In this case, the solution is to put a listener in Zone Extension and when poss to receive communications, room extensions. Then we use handleInternalMessage. Would that be correct.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 20 guests