_server.setRoomVariables

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

Moderators: Lapo, Bax

User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

_server.setRoomVariables

Postby BigFIsh » 07 May 2008, 08:28

Just one quick question. According to the documentations, sendUpdate means sending update to all clients in the room. I think the user has to be in that specific room to recieve updates, correct?

Now I'm wondering.. can this be achieved regardless to the room the client is in? i.e. send update to everyone in the Zone, automatically, after the variables are changed via serverside?

I can do a walkaround but it's rather messy..

So close, so close.. :D
User avatar
Lapo
Site Admin
Posts: 21228
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: _server.setRoomVariables

Postby Lapo » 07 May 2008, 15:46

BigFIsh wrote:Just one quick question. According to the documentations, sendUpdate means sending update to all clients in the room. I think the user has to be in that specific room to recieve updates, correct?

sendUpdate?
That doesn't exist. You refer to room variables?

Now I'm wondering.. can this be achieved regardless to the room the client is in? i.e. send update to everyone in the Zone, automatically, after the variables are changed via serverside?


:?: It's not clear
RoomVariables updates interest the room in which those variables are updates. Outside of the rooms users should know nothing.

Maybe you can better explain?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 07 May 2008, 19:48

Sure :)

I have similar problem to Ross Przybylski after reading her situation. About people joining game that has already started.


This is what I'm trying to do:

1. Upon the request from the client to start the game, the client sends a message to the server "begin game"
2. When the server recieves this message, I'm trying to use the "_server.setRoomVariables(...) to set the "game started" flag to true, then send the new update to all clients, regardless of the room they is in. Then upon recieving the new update, each client's game list will be updated according to the new value. I don't need to recieve a full game list again from the server, all I have to change the value that contains inside my dataprovider. That is, from 0 to 1.

But, after reading about sendUpdate (a property of _server.setRoomVariables) - i found out that it means "sending an update to all clients in the room where the variables were changed.", so perhaps I can't get this to work.

My walkaround at the moment is: When server recieves the request: "Begin game!", server updates the new room variable for that room, and then find all users in the zone then send a str message to them telling them to change the value from 0 to 1 in the dataprovider. Then when the client tries to join that room, which has a value of "1" - a error pops up saying - tsk tsk, game already started! :D

Maybe this is a better way to do things.. as if each client recieves the "smartfox.onRoomVariablesUpdate(), then they'll have to get the whole variable list... bandwidth bandwidth..



I heard you said something about improving room management in server side. May i ask.. in what ways?
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 08 May 2008, 14:10

Look fish, Personally I suffered a lot with room variables. I tried them in all ways, and each time I come with some type of problem, so my personal advice and what I`m currently doing is using room variables as the name implies only for things that have to do only with things inside that room where only people who can read/change those values are only inside the room.

For updating users in a lobby, I work with normal _server.sendResponse() and send the response to the users in the lobby room. passing along all the necessary data like: the id of the gameRoom that needs to be updates, the positionId of the user who left/joind
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 08 May 2008, 19:43

I suffered a lot with room variables.


Me too, me too. :lol:

But I finally figured out how to receive all server-made variables when smartfox.onRoomAdded is called, regardless of which room the clients are in. That was what I was trying to achieve as it was very important.

That's why I love programming, there's always walkarounds in every situation. Messy or not. Althrough I perfer not messy :lol:
yumsai
Posts: 8
Joined: 07 May 2008, 18:22

Postby yumsai » 08 May 2008, 20:57

hey, i have the same question like you..

for example, i would like to tell everyone ...the "total online user" to everyone once there is a new user login into the system.

Or say, the server can broadcast a specify value/variable when it is changed.

i want to know how to do it......
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 09 May 2008, 01:37

Sure,

You need a server side extension. i.e. inside your <zone></zone> in config.

In the extension, we have a function called HandleInternalEvent(evt). Have if "evt.name == "userJoin". This will be called everytime a user joins a zone where the extension is located.

use this: _server.getCurrentZone() to get the zone. Let's set it to a variable called "zone".

then..

zone.getRooms() to get all the rooms in the zone. Let's set it to a variable called "rooms" which will hold an array for all the rooms in the zone.

And perform a "for (var r in rooms) {..} loop" to loop through each room in the zone. Then for each room, you have rooms[r].getAllUsers(). Set it to a variable.. say.. "users" Then, still within the loop, get the server to send the new variable to "users" which represent an array of all users in that room. _server.sendResponse(object, -1, null, users)

The client will recieve this message through onExtensionResponse.

You could have restrictions, for example.. if rooms[r].isGame() is true, then don't send any message to that room. Same goes for rooms[r].isLimbo().

Code: Select all

function handleInternalEvent(evt) {
   if (evt.name == "userJoin") {
      var zone = _server.getCurrentZone()
      var rooms = zone.getRooms()
      for (var r in rooms) {
         if (!rooms[r].isGame()) {
            var users = rooms[r].getAllUsers()
            var res = {}
            res._cmd = "update";
            res._upd = "Hello world!"
            _server.sendResponse(res, -1, null, users)
         }
      }
   }
}


Or you could use this instead: zone.getUserCount(). I think you should be able to do this from client side. Simply get the current zone using smartfox.getCurrentZone(), and then call getUserCount(). You could perform this action every 20 seconds using setIntervals. Not sure if this will work.[/code]
User avatar
Lapo
Site Admin
Posts: 21228
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 May 2008, 06:24

Look fish, Personally I suffered a lot with room variables. I tried them in all ways, and each time I come with some type of problem, so my personal advice and what I`m currently doing is using room variables as the name implies only for things that have to do only with things inside that room where only people who can read/change those values are only inside the room.

The problem of seeing room variables outside their rooms has been vastly discussed in this board, and it's probably one of the most popular :)

RoomVariables are a mechanism for keeping custom data in a Room and get it updated as soon as it changes. Reading those variables from outside the room means that the server has to continuously update all the clients in the Zone to keep them up to date.

Unfortunately this approach is not scalable. As soon as the traffic increases these update broadcasts will eat just too much bandwidth and server resources.

We are planning to enhance the system by allowing a finer grained configuration of Room Variables in order to solve some of the most requested features. Possible ideas are to allow developers to specify in each variable which rooms should listen for changes, including an option for "all rooms".

Developers will anyway have to take into consideration the impact of these settings on the general resources/bandwidth usage, and for certain tasks using custom server side code is still the best option.

One example of using server side code comes from another discussion that was started in this same board, recently. The developer was in need to show all users inside a game room and for each user he also needed various informations (name, user variables etc...)

He expected to have all these informations were already populated in the client side API, so that he could simply get any variable from any room, every user etc...
What he wasn't realizing is that, in order to keep all this data available on the client side, the server would have to transfer tons of updates on every second to every connected user, eating up humongous quantities of bandwidth and server resources.
It would be just a broadcast-all scenario, where every change in every user/room is fired to everyone.

Suppose you have 1000 connected users and let's say we have an average of 10 variables changing on every second: we'll have to fire 10 x 1000 = 10.000 messages per second. If each message is 100 bytes we'll end with a traffic of 8Mbits/s ( == 1MByte/s ) only for keeping the Lobby up to date (!)

The solution to this issue is that we of course don't transfer all that data automatically, but we do on-demand.
In your lobby you can show the game room names and properties (users, watchers) by using the default API functions. When you want to see more details for that room you click on it: at this point we call our extension and ask for all the current details for that room and show it (including the user list)

If you want you can add an extra depth-level by allowing the user to click on any player and again ask the server to send all relevant data about it.

This way we can definitely optimize the resource usage without sacrificing any advanced feature in the application.

Additionally if there are values outside of the default ones provided by the API for users and rooms, you can use a custom extension to send them in real-time or by using an interval-based push from the server side.

Hope this helps
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 09 May 2008, 07:46

That was very helpful Lapo! :D

allow developers to specify in each variable which rooms should listen for changes, including an option for "all rooms".


I'll be looking forward to that. Thanks Lapo.
[/quote]
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 13 May 2008, 10:30

thanks Lapo for the information but:

I think it is a common approach in online turn-based multiplayer games that in the lobby you see at least the created games, the seats in them and who is on which seat. and when a user joins/leaves/PC takeover..etc those updates has to be updated in the lobby, that was what I suffered to do with room variables and dealt with it eventually using serverside extension, I agree with you about the bandwidth issue, but that should be clear in the documentations (the scope of RoomVars and the overhead of using them)
User avatar
Lapo
Site Admin
Posts: 21228
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 13 May 2008, 11:42

This document should be clear:
http://www.smartfoxserver.com/docs/docP ... ecture.htm

Where it talks about RoomVariables:
One of the most important features of Rooms is the ability to attach custom values to them, the so called Room Variables. These values can be set from both the client side and the server side and they can be very helpful to maintain the state of a Room.


... and a little later:
Room Variables are immediately available to all clients joining the Room and their change is notified in real time to all clients.


We'll more references to this document in all other sections of the docs where we talk about Room Variables
Lapo

--

gotoAndPlay()

...addicted to flash games
warhell
Posts: 199
Joined: 18 Aug 2007, 16:49
Location: Silicon Valley, CA
Contact:

Postby warhell » 30 May 2008, 14:34

I have the exact same problem! I have a lobby, and in my game list I want to show not only the number of players and the game name, but also who is in it and other options, all which are stored in the room variables of each room.

NOOOOOOOOOOO! WHYYYYYYYYYYYY!?

I hope you do implement that feature that allows room variables to be seen outside their rooms sooooooooooon!

What sucks even more, I'm using basic, so I can't use extensions :(.
Sandyx
Posts: 21
Joined: 06 Sep 2008, 10:54

Postby Sandyx » 18 Sep 2008, 09:09

Possible ideas are to allow developers to specify in each variable which rooms should listen for changes, including an option for "all rooms".


do we have a plan still on for this ... :) .... in the lobby need to show the "gameState" ... started .. waiting etc etc etc
User avatar
Lapo
Site Admin
Posts: 21228
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 09:39

follow the tips posted here -> viewtopic.php?p=12388#12388
Lapo

--

gotoAndPlay()

...addicted to flash games
Sandyx
Posts: 21
Joined: 06 Sep 2008, 10:54

Postby Sandyx » 18 Sep 2008, 09:51

you posted a link the top we already are on ...
:D

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 11 guests