Multiple Rooms or not Multiple Rooms?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

didibus
Posts: 34
Joined: 09 Sep 2007, 19:31

Multiple Rooms or not Multiple Rooms?

Postby didibus » 15 Mar 2008, 08:51

Strangely, I have a feeling that multiple rooms are a cause for trouble, and lots of it. You know, allowing Users to join more then one room at the same time. Now I came to a dilemma where it seems mostly logical to use multiple rooms. But do I really want to use them?

So I was wondering, what's the deal with multiple rooms. What exactly do they complicate and what trouble could arise from using them?

Also, on a performance level, does it impact in anyways server load?

Should I use them without worry, or avoid them by design?

thank you
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Mar 2008, 10:55

Nice question.
Actually having each client joined in one room at a time simplifies the developer work a lot.
Choosing to use multiple rooms can have advantages in certain scenarios but it can make the development more tricky.

One possible scenario in which multiple rooms are needed is when you want the user to always be present in the main Lobby but also play games with friends.
This would imply that each user will at least be present in two rooms at once.

The API only provide automatic room detection for single-room development. What does this mean?
It means that the when you send a public message with sendPublicMessage() you don't need to specify in which room ... the client API already know where you are...
... unless you have joined two or more rooms. In this case the API can't guess where you want to send the public message and so you will have to pass an extra parameter.

This is valid for all methods in the SmartFoxClient class which in turn implies that your code will have to manage the rooms that the client is in.
Same idea applies to the server side extension.

So yes, you should carefully plan in advance if you really need this feature or if you can implement the application without multiple rooms.

Also, on a performance level, does it impact in anyways server load?

In general I'd say yes.
If you think about the scenario mentioned above (Lobby + multiple game rooms) each client will not only receive the game updates but also the lobby updates etc... so there's more traffic and bandwidth used as well as more work for the server

hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 18 Mar 2008, 02:32

Nice question and nice explanation Lapo :D
I'll be posting very soon a great example of joining multiple rooms using SFS Pro. Exactly like Lapo explained, a user that joins a lobby while also joins a game room. In my case I made it in a very interesting way:
The user joins what I called "the main room" and ALWAYS stays there, but doesn't necessarily send any public messages or updates from that room.
After the user joins the main room, he will then automatically joins the lobby afterwards. When he joins a game, he will leave the lobby and go to the game room, but he will REMAIN on the main room at all times.
Why is that?
Performance: the main room works almost as a "limbo" room. It stays there for one propose: Update user var stats and allow players to send private messages to each other wherever they are. There is no public messages or extra broadcasts. Just a connection between users.

One thing I'm still trying to figure out is how to prevent multiple broadcasts when a user variable updates.
On the example above you will see what I'm talking about:

Code: Select all

[Received]: <msg t="sys"><body action="uVarsUpdate" r="1"><user id="18" /><vars><var n="inGame" t="n">0</var><var n="chatRoom" t="n">1</var></vars></body></msg>
[Received]: <msg t="sys"><body action="uVarsUpdate" r="3"><user id="18" /><vars><var n="inGame" t="n">0</var><var n="chatRoom" t="n">1</var></vars></body></msg>
[Received]: <msg t="sys"><body action="uVarsUpdate" r="20"><user id="18" /><vars><var n="inGame" t="n">0</var><var n="chatRoom" t="n">1</var></vars></body></msg>
[Received]: <msg t="sys"><body action="uVarsUpdate" r="2"><user id="18" /><vars><var n="inGame" t="n">0</var><var n="chatRoom" t="n">1</var></vars></body></msg>


As you can see, even thou all my users are connected to a "main room", they all receive the uVarsUpdate event from all rooms that user is logged in. If there is an option to prevent this broadcast, I'd be happy to know :D
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Mar 2008, 06:55

I see. UserVariables are attached to the user so if he's in multiple rooms it's necessary to update all the people in those rooms.
Maybe we could add an extra parameter to the setUserVariables that forces the update only in the specified room.
Would this help?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 18 Mar 2008, 16:24

Lapo wrote:I see. UserVariables are attached to the user so if he's in multiple rooms it's necessary to update all the people in those rooms.
Maybe we could add an extra parameter to the setUserVariables that forces the update only in the specified room.
Would this help?


O yes yes that would help quite a lot :) I mean, for now I'm just working locally and I haven't made the new version public yet, but I think when we have 200 players connected all joining and leaving game rooms, this could be a problem.
Want me to post it in the wish list forum?
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 20 Mar 2008, 07:19

No, it's okay. I've already filed it in the to-do system :)
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 08 Oct 2009, 18:40

Code: Select all

No, it's okay. I've already filed it in the to-do system Smile
Thanks


Sorry to bring this topic back to life Lapo, but I was running into this exact problem on SFS 1.6.6 and tried to find any updates related to this but couldn't. Was this feature implemented somehow?
And if not, is there a way to avoid multiple room broadcasting on vars update?
SELECT * FROM users WHERE clue > 0
0 rows returned.
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Oct 2009, 07:48

Sorry no, this is feature is not available as of now.
Actually the feature involves some architectural changes that will take place in the next major release of SmartFoxServer. (no release dates available)
Lapo

--

gotoAndPlay()

...addicted to flash games
Himmelweiss
Posts: 7
Joined: 25 Oct 2009, 10:04
Contact:

Postby Himmelweiss » 25 Oct 2009, 10:11

Lapo wrote:Sorry no, this is feature is not available as of now.
Actually the feature involves some architectural changes that will take place in the next major release of SmartFoxServer. (no release dates available)


I would be also interested in this feature, would be quite useful since my Users also stay in the Lobby room while playing in an gameroom and it is a bit sad that there is no room parameter for setUserVariables.

However, there are workarrounds so it's no big deal, but it would be still very userful.
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 25 Oct 2009, 17:05

Hi,
this topic is particularly interesting to me.

There is one major "philosophical" problem with this option.
User Variables are custom values attached to Users, so wherever a certain User is anyone should be able to "see" the latest up-to-date values for that client.

When you need to introduce a room parameter into this it feels like you are probably in need of a Room Variable for that User not a real User Variable.
See what I mean?

Also, when sending a UserVariableUpdate to the other clients it is only necessary to find all those who are at least in one room with that User, in other words those who can "see" him.
This way only one update is sent to all interested parties.
But I wouldn't exclude some of them or they won't be in synch with those values.

Hope I made myself clear.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Rax
Posts: 39
Joined: 07 Jun 2008, 19:46

Postby Rax » 26 Oct 2009, 20:08

Lapo wrote:I see. UserVariables are attached to the user so if he's in multiple rooms it's necessary to update all the people in those rooms.
Maybe we could add an extra parameter to the setUserVariables that forces the update only in the specified room.
Would this help?


Would there be a way to also just prevent the multiple broadcasts?

For example, if you set a user variable and you are in two rooms and another user is in the same two rooms, could you make it so smart fox sends the user variable update to the first room then when it gets to the second room it doesn't send the update to the users who already received it?

I have a problem because I am making a game with many areas.

Image

I wanted to make each area a room so when you moved into a new area you would just log into a new room and automatically get all the user information for the other users in that room. The problem, as you can see from the above image, is that a user can be in multiple areas at once. This isn't a problem thanks to the ability to be in multiple rooms. It is a problem since users often receive the same update from the same user multiple times.

Is there anyway around this right now or do I need to wait for Smart Fox to be updated?
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Oct 2009, 16:34

For example, if you set a user variable and you are in two rooms and another user is in the same two rooms, could you make it so smart fox sends the user variable update to the first room then when it gets to the second room it doesn't send the update to the users who already received it?

In the latest versions of SmartFoxServer PRO (1.6.5+) the update is sent once to all users that are interested in the change. If you use the multiroom feature the server will anyways one update only to each client.
Maybe you are using an older version?

Also you can enable the <UserVarsOptimization>true</UserVarsOptimization> setting (available since 1.6.3) to optimize the variables update. Only changed variables are broadcast
Lapo

--

gotoAndPlay()

...addicted to flash games
khambadkone
Posts: 7
Joined: 28 Feb 2008, 10:55
Location: India
Contact:

which room gets sent as fromRoom in handleRequest

Postby khambadkone » 07 Nov 2009, 07:56

Finding this thread, I was curious about the following situation :

We have a common Lobby with a game room created for players to play a game. When the player joins the gameroom, he's in two rooms at a time.

The game allows a player to request to exit a game. For this, a client message is sent called ChangeOpponent, and gets handled by the extension.

Which room ID is passed in the fromRoom parameter to handleRequest? Is it always guaranteed to be the game Room's ID ?

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 13 guests